【发布时间】:2014-12-25 23:33:24
【问题描述】:
我知道这个问题很简单,但是如果不创建步骤对象就找不到解决方案,我想要一个单行代码,或者尽可能简单的代码。
假设我有一个名为 df 的数据框,其中包含 x、y、z 列:
x<-c(rep('place1',33),rep('place2',33),rep('place3',34))
y<-sample(c('type1','type2','type3','type4','type5'),100,replace=T)
z<-sample(40:80,100,replace=T)
df<-data.frame(x,y,z)
我想为 x 和 y 的每个级别组合获取所有可能的 z 子集(type1 in place1,type2 in place1, type3 in place1...type4 in place3 和 type5 in place3)。像这样的:
[[place1]]
[type1]
[1] 57 73 74 47 52 61
[type2]
[1] 72 76 64 62 73 75
...
[type5]
...
[[place3]]
[type1]
...
[type5]
如果这是可能的,我如何访问每个子集?
我尝试在lapply 中嵌套split,但没有成功。
很抱歉这个简单的问题,但找不到合适的解决方案。
任何帮助将不胜感激。
【问题讨论】: