I have a data frame which has the following elements and I want to have a subset of records.
location <- c('london', 'london','london', 'newyork' ,'newyork', 'paris', 'delhi')
year<- c(1990, 1991, 1992, 2001, 2002, 2003,2001)
df<- data.frame(location,year)
and I have a vector say
x<- c('newyork', 'delhi')
I want to subset the data frame such that the final data frame contains all elements except the location that are not listed in x. I would like to create a test data frame, I have tried this
test1 <- df[df$location %in% c('newyork','delhi'), ]
It gives me the opposite. Can some one help?
I am expecting the output like this:
location year
london 1990
london 1991
london 1992
paris 2003