Entering edit mode
4.1 years ago
shelley.w.peterson
▴
10
I'm working in R and I have a data.frame that looks like this:
v1 v2 v3
1 131 456
2 4 131
3 685 184
4 124 384
5 13184 2
and I have a list of numbers that I want removed:
Bad <- paste(c("13584", "131", "40", "134"))
and I am trying to remove any rows from the data.frame that have any of the "bad" numbers in V2
I've tried:
new.df <- df %>% filter(!str_detect(df$V2, Bad))
Which removes both lines 1 and 5, when I want just line 1 to be removed. I've tried using fixed(Bad) and it gives me the same result.
I've also tried:
new.df <- df[-match(Bad,df$V2)]
Which gives the error "only 0's may be mixed with negative subscripts" and any regex things I've tried to add have just given me errors.
new.df <- df[!df$V2 %in% Bad]
gives me "error: undefined columns selected"
Please help!