1

Sorry for the silly question, but I have a huge dataframe (called "totaldecade") with columns named:

Event.ID,Event.Date,CAMEO.Code

I want to delete all rows that have number ranges: 10:58, 90:145, 1011:1454, 160:166, 1661:1663, within the CAMEO:Code column.

I have tried:

totaldecade[with(totaldecade, !((CAMEO.Code %between% 10:58) | 
(CAMEO.Code %between% 90:145) | 
(CAMEO.Code %between% 1011:1454) | (CAMEO.Code %between% 160:166) | 
(CAMEO.Code %between% 1661:1663))), ]

But doesn't seem to work.

Any help is appreciated!

Michelle

Saurabh Chauhan
  • 3,161
  • 2
  • 19
  • 46

1 Answers1

0

We get the ranges in a vector, use %in% to create the logical vector and negate (!) to change the FALSE elements to TRUE and viceversa

library(dplyr)
totaldecade %>% 
       filter(!CAMEO.Code %in% c(10:58, 90:145, 1011:1454, 160:166, 1661:1663))

Or using subset from base R

subset(totaldecade, !CAMEO.Code %in% c(10:58, 90:145, 1011:1454, 
                    160:166, 1661:1663))
akrun
  • 874,273
  • 37
  • 540
  • 662