R ddply()

1 개요[ | ]

R ddply()
library(plyr)
df = data.frame(x1=c(0,1,1,1,2,3,3,3),
                x2=c(0,1,1,3,2,3,3,2),
                x3=c(0,1,1,1,2,3,3,2))
df
##   x1 x2 x3
## 1  0  0  0
## 2  1  1  1
## 3  1  1  1
## 4  1  3  1
## 5  2  2  2
## 6  3  3  3
## 7  3  3  3
## 8  3  2  2

ddply(df, .(x1, x2, x3), nrow)
##   x1 x2 x3 V1
## 1  0  0  0  1
## 2  1  1  1  2
## 3  1  3  1  1
## 4  2  2  2  1
## 5  3  2  2  1
## 6  3  3  3  2
table()과 ddply()
library(plyr)
table(baseball[1:100,]$year)
##
## 1871 1872 1873 1874 1875 1876 1877 1878 
##    7   13   13   15   17   15   17    3
ddply(baseball[1:100,], ~year, nrow)
ddply(baseball[1:100,], 'year', nrow)
ddply(baseball[1:100,], .(year), nrow)
##   year V1
## 1 1871  7
## 2 1872 13
## 3 1873 13
## 4 1874 15
## 5 1875 17
## 6 1876 15
## 7 1877 17
## 8 1878  3

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}