2017-09-28 7 views
-1

私はすべての行がリストであるデータフレームに列を持っています。排除によって列から特定の値を削除することは可能ですか?除外によってリストから要素を削除します

私はベクトルのために、以下のアプローチを試してみました:

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

しかし、私は次のエラー得た:最初の4行の

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 

例:ここで

> dput(head(yelp_asian_final$categories,4) 
+) 
list(c("Thai", "Restaurants"), c("Vietnamese", "Restaurants"), 
    c("Indian", "Restaurants"), c("Restaurants", "Japanese", 
    "Sushi Bars")) 
+3

[偉大R再現性の例を作るには?](http://stackoverflow.com/questions/5963269) – Sotos

答えて

1

をアイディア:dplyr

library(dplyr) 

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

v1        data 
1 1    Indian, Restaurants 
2 5 Restaurants, Japanese, Sushi Bars 
3 6      Restaurants 
4 9      Restaurants 
関連する問題