The standard way to remove multiple items from a data frame

What is the best way to remove multiple items from a data framework? In my case, I have all days of the month in the data frame and you want to delete several days. Something like below works fine for one day.

m[m$date!="01/31/11",] 

However, if I try something like

 m[m$date!=c("01/31/11","01/30/11"),] 

I get a warning message

 Warning message: In `!=.default`(m$date, c("01/31/11", "01/30/11")) : longer object length is not a multiple of shorter object length Calls: [ ... [.data.frame -> Ops.dates -> NextMethod -> Ops.times -> NextMethod 

It seems to work two days, but if I add 01/29/11 to the vector, it shows all the days, but 01/31/11.

+13
r
Sep 21 2018-11-11T00:
source share
3 answers

nzcoops is on site with his offer. I asked this question in R Chat a while ago, and Paul Tetor suggested defining a new function:

 `%notin%` <- function(x,y) !(x %in% y) 

which can then be used as follows:

 foo <- letters[1:6] > foo[foo %notin% c("a", "c", "e")] [1] "b" "d" "f" 

Needless to say, this little gem is now in my R profile and is used quite often.

+32
Sep 21 '11 at 11:17
source share

I think you want:

 m[!m$date %in% c("01/31/11","01/30/11"),] 
+13
Sep 21 '11 at 5:15
source share

A cool way is to use the Negate function to create a new one:

 `%ni%` <- Negate(`%in%`) 

than you can use it to search for disjoint elements

+2
Apr 11 '13 at 10:30
source share



All Articles