-1

I have a column in my data frame in which every row is a list. Is it possible to remove certain values from the column by exclusion?

I have tried the following approach for vectors:

yelp_asian_final %>% mutate(categories = ifelse(categories != "Thai" | categories != "Vietnamese", NULL, 
categories))

But I got the following error:

Error in mutate_impl(.data, dots) : 
  Evaluation error: replacement has length zero.
In addition: Warning message:
In rep(yes, length.out = length(ans)) :
  'x' is NULL so the result will be NULL

Example of the first 4 rows:

> dput(head(yelp_asian_final$categories,4)
+ )
list(c("Thai", "Restaurants"), c("Vietnamese", "Restaurants"), 
    c("Indian", "Restaurants"), c("Restaurants", "Japanese", 
    "Sushi Bars"))
Hadsga
  • 185
  • 2
  • 4
  • 15
  • 3
    [How to make a great R reproducible example?](http://stackoverflow.com/questions/5963269) – Sotos Sep 28 '17 at 12:04

1 Answers1

1

Here is an idea via dplyr,

library(dplyr)

df1 %>% 
 unnest() %>% 
 filter(v2 != 'Thai'& v2 != 'Vietnamese') %>% 
 nest(v2)

which gives,

  v1                              data
1  1               Indian, Restaurants
2  5 Restaurants, Japanese, Sushi Bars
3  6                       Restaurants
4  9                       Restaurants
Sotos
  • 51,121
  • 6
  • 32
  • 66