按照某列的值拆分data.frame
My data is like this (for example):
ID Rate State
1 24 AL
2 35 MN
3 46 FL
4 34 AL
5 78 MN
6 99 FL
I want to split the data by state and I want to get 3 data sets like below:
data set 1 ID Rate State 1 24 AL 4 34 AL data set 2 ID Rate State 2 35 MN 5 78 MN data set 3 ID Rate State 3 46 FL 6 99 FL
split( df , df$State )
$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 MNmylist <- split( df , df$State ) ;
mylist[[1]]
mylist[[2]]
mylist[[3]]
REF:
http://stackoverflow.com/questions/19327020/in-r-how-to-split-subset-a-data-frame-by-factors-in-one-column