Split/subset a data frame by factors in one column [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-27 04:03:29
Simon O'Hanlon

We could use split:

mylist <- split(df, df$State)

mylist
$AL
  ID Rate State
1  1   24    AL
4  4   34    AL

$FL
  ID Rate State
3  3   46    FL
6  6   99    FL

$MN
  ID Rate State
2  2   35    MN
5  5   78    MN

To access elements number:

mylist[[1]]

or by name:

mylist$AL
  ID Rate State
1  1   24    AL
4  4   34    AL

?split

Description

split divides the data in the vector x into the groups defined by f. The replacement forms replace values corresponding to such a division. unsplit reverses the effect of split.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!