library(plyr)
a<-data.frame(a=rep(c(1,1,2),each=3),b=letters[1:9])
head(a)
# a b
#1 1 a
#2 1 b
#3 1 c
#4 1 d
#5 1 e
#6 1 f
b<-split(a$b,a$a)
b
$`1`
[1] a b c d e f
Levels: a b c d e f g h i
$`2`
[1] g h i
Levels: a b c d e f g h i
d<-ldply(b,as.data.frame)
d
.id X[[i]]
1 1 a
2 1 b
3 1 c
4 1 d
5 1 e
6 1 f
7 2 g
8 2 h
9 2 i
网友评论