美文网首页ggplot集锦
split的逆运算可以用plyr::ldply解决

split的逆运算可以用plyr::ldply解决

作者: 一只烟酒僧 | 来源:发表于2021-02-01 12:27 被阅读0次
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

相关文章

网友评论

    本文标题:split的逆运算可以用plyr::ldply解决

    本文链接:https://www.haomeiwen.com/subject/qtpjtltx.html