按照某列的值拆分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 MN
mylist <- split( df , df$State ) ;
mylist[[1]]