[英]How do I subset a list with mixed data type and data structure?
我有一个列表,其中包含数据类型(字符)和数据结构(数据帧)的混合。
我只想保留数据框并删除其余的。
> 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
根据示例,OP的list
元素可能是vectors
并且想要删除any
具有“错误”子字符串的元素
list[!sapply(list, function(x) any(grepl("error$", x)))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.