I'm importing a sav file to RStudio. Now I want to select only a specific nation (column header: nation
) and a specific year (column header: year
). Using following code:
myfile_nation_year <- subset(myfile, (nation == "Great Britain") & (year == "2012"))
I only get this error message:
Error in subset.default(sigma_org, (nation == "Great Britain") & (year == :
object 'nation' not found
When I look at my file in the Viewer the header appears with nation, year and the other headers.
I also tried:
myfile_nation_year <- subset(myfile, (myfile$nation == "Great Britain") & (myfile$year == "2012"))
I get no error message but an empty list. I bet it's a piece of cake for someone experienced, but I'm new to R and don't know what I did wrong.
str(myfile)
List of 3184
$ nation : Factor w/ 20 levels "France","Germany",..: 1 1 1 1 1 1 1 1 1 1 ...
$ region : Factor w/ 9 levels "Europe","USA",..: 1 1 1 1 1 1 1 1 1 1 ...
$ city_chn : Factor w/ 23 levels "Beijing","Shanghai",..: NA NA NA NA NA NA NA NA NA NA ...
$ citych_tiers : Factor w/ 5 levels "Else","Tier 1",..: NA NA NA NA NA NA NA NA NA NA ...
$ year : Factor w/ 8 levels "2007","2008",..: 8 8 8 8 8 8 8 8 8 8 ...