【发布时间】:2014-10-03 17:38:53
【问题描述】:
我在 R 中有一个列表列表;每个列表都有一个 Grep 命令的结果,指示找到搜索字符串的位置。命令
> matches<-lapply(ListOfFiles, function(x)
+ grep("SearchString",readLines(x),ignore.case = T))
生产
//I copy the results that the function actually yields for the sake of the example
> matches<-list(c(11L, 13L), c(9L, 12L, 14L, 15L, 16L, 19L, 20L, 22L, 25L
+ ), c(5L, 8L, 11L), c(10L, 11L, 13L, 14L, 16L), c(5L, 7L, 9L),
+ integer(0))
> matches
[[1]]
[1] 11 13
[[2]]
[1] 9 12 14 15 16 19 20 22 25
[[3]]
[1] 5 8 11
[[4]]
[1] 10 11 13 14 16
[[5]]
[1] 5 7 9
[[6]]
integer(0)
我需要将其转换为 6 行 1 列的简单数据框,每个“单元格”都包含 matches 的 6 个列表中的每个列表的总和。
如果可能,请尝试解释我应该使用的语法;我是 R 新手,有时如果同时嵌套多个内容,我会发现示例难以理解。
【问题讨论】:
标签: r list dataframe nested-lists