3
我需要有关如何以迭代方式管理列表的帮助。将函数应用于R中的数据框列表
我有以下列表list
它由几个相同的列,但行数不同的数据帧组成。示例:
[[1]]
id InpatientDays ERVisits OfficeVisits Narcotics
1 a 0 0 18 1
2 b 1 1 6 1
3 c 0 0 5 3
4 d 0 1 19 0
5 e 8 2 19 3
6 f 2 0 9 2
[[2]]
id InpatientDays ERVisits OfficeVisits Narcotics
7 a 16 1 8 1
8 b 2 0 8 0
9 c 2 1 4 3
10 d 4 2 0 2
11 e 6 5 20 2
12 a 0 0 7 4
我想应用一个函数来获取列表中每个“数据框”的id的所有可能组合。
我打算尝试这样的事情lapply(list1, function(x) combn(unique(list1[x]$id)))
这当然不行..期待得到的东西,如:
[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15]
[1,] "a" "a" "a" "a" "a" "b" "b" "b" "b" "c" "c" "c" "d" "d" "e"
[2,] "b" "c" "d" "e" "f" "c" "d" "e" "f" "d" "e" "f" "e" "f" "f"
[[2]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "a" "a" "a" "a" "b" "b" "b" "c" "c" "d"
[2,] "b" "c" "d" "e" "c" "d" "e" "d" "e" "e"
这可能吗?我肯定知道这个工程的一个数据帧df
combn(unique(df$id),2)
不知你已经注意到您的[近期](http://stackoverflow.com/posts/36066336/revisions)[问题](http://stackoverflow.com/posts/36048558/revisions)的重复某种模式...也许[this ](http://stackoverflow.com/tags/dataframes/info)有点帮助? –