我有一个列表,其中包含数据类型(字符)和数据结构(数据帧)的混合。
我只想保留数据框并删除其余的数据框。
> head(list)
[[1]]
[1] "/Users/Jane/R/12498798.txt error"
[[2]]
match
1 Japan arrests man for taking gun
2 Extradition bill turns ugly
file
1 /Users/Jane/R/12498770.txt
2 /Users/Jane/R/12498770.txt
[[3]]
[1] "/Users/Jane/R/12498780.txt error"
我希望最终列表仅包含数据帧:
[[2]]
match
1 Japan arrests man for taking gun
2 Extradition bill turns ugly
file
1 /Users/Jane/R/12498770.txt
2 /Users/Jane/R/12498770.txt
答案 0 :(得分:0)
根据示例,OP的list
元素可能是vectors
,并且想要删除具有“错误”子字符串的any
元素
list[!sapply(list, function(x) any(grepl("error$", x)))]