I am trying to access the R variables in a loop in the following way
bes2 = data.frame("id"=c(1,2), "generalElectionVoteW1"=c("Labour","Bla"),
"generalElectionVoteW2"=c("x","t"))
general_names <- c("generalElectionVoteW1", "generalElectionVoteW2")
labour_w = bes2[bes2$general_names[1] == "Labour",]
Which will simply result in an empty vector.
general_names
is simply used to keep generalElectionVoteW1, ...W2 and many more saved for easier access in a loop.
However if I access them manually like labour_w = bes2[bes2$generalElectionVoteW1 == "Labour",]
it works as desired. Where is my mistake?
bes2:
id generalElectionVoteW1 generalElectionVoteW2
1 1 Labour x
2 2 Bla t
general_names:
"generalElectionVoteW1" "generalElectionVoteW2"