I have a very simple problem and somehow I cannot solve it, despite two hours of trying to do so. Short of sending you the data, I have to explain my problem with words and very little code.
I have a dataframe (elecData
) with several variables and a factor (Partido
). All I want to do is to create a new dataframe selecting one factor level (Podemos
), so that I have a dataframe in which only rows containing Podemos
as a factor of Partido
are present. The code I use is the following:
PodemosSort=subset(elecData, subset=elecData$Partido=="Podemos")
For some reason, the new dataframe does not select only the intended level (Podemos
), but all levels of the factor. Moreover, I have used the subset function on a simple dataframe I made up to see if it works and it did. Why is it not working in this case?
Thank you in advance.