【发布时间】:2016-11-04 14:05:38
【问题描述】:
head(per1)
flowcorrelativeid nrodocumento grupo_fict cod_jer
21 431167 49574917 3 1146
49 546385 54692750 1 320
50 546388 48552750 2 320
54 454662 54731807 8 104
58 484984 17549854 4 104
78 360883 46867674 1 101
79 360883 56864674 7 101
80 360883 46867668 1 258
81 360883 66847668 5 258
81 360883 57364201 1 178
88 360883 58364201 6 178
我有这个数据框,我想生成这个数据框的很多子集,如下所示:
data_frame_104_1=subset(per1,per1$cod_jer==104 & per1$grupo_fict=1)
data_frame_104_2=subset(per1,per1$cod_jer==104 & per1$grupo_fict=2)
.
.
.
data_frame_104_8=subset(per1,per1$cod_jer==104 & per1$grupo_fict=8)
然后
data_frame_101_1=subset(per1,per1$cod_jer==101 & per1$grupo_fict=1)
data_frame_101_2=subset(per1,per1$cod_jer==101 & per1$grupo_fict=2)
.
.
.
data_frame_101_8=subset(per1,per1$cod_jer==101 & per1$grupo_fict=8)
每个“cod_jer”(52 组)和每个“grupo_fict”(8 组)都需要这个
我该怎么办?
有什么建议吗?
谢谢!
【问题讨论】:
-
只需使用
split即split(per1, list(per1$cod_jer, per1$grupo_fict), drop=TRUE)并获得data.frames的list顺便说一句,如果您需要根据这两列进行汇总,您可以在没有任何split的情况下使用group_by操作