"R table()"의 두 판 사이의 차이

50번째 줄: 50번째 줄:
##  2  2  2  
##  2  2  2  
</source>
</source>
{{소스헤더|table()과 ddply()}}
<source lang='r'>
<source lang='r'>
library(plyr)
library(plyr)

2019년 5월 11일 (토) 19:33 판

1 개요

R table()
벡터
x <- c(3,1,4,1,5,2,6,5)
table(x)
## x
## 1 2 3 4 5 6 
## 2 1 1 1 2 1
table( c(3,1,4,1,5,2,6,5) )
## 
## 1 2 3 4 5 6 
## 2 1 1 1 2 1
데이터프레임$컬럼
v <- c(1, 'hello', 1, 'world', 'hello')
table(v)
## v
##     1 hello world 
##     2     2     1
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Class  Name variable value
    A Alice  English    90
    A   Bob  English    80
    B  Dave  English    60
    A Alice     Math    60
    B Carol     Math    80
    B  Dave     Math    90
")
scores
##   Class  Name variable value
## 1     A Alice  English    90
## 2     A   Bob  English    80
## 3     B  Dave  English    60
## 4     A Alice     Math    60
## 5     B Carol     Math    80
## 6     B  Dave     Math    90

table( scores$variable )
## English    Math 
##       3       3 

table( scores$value )
## 60 80 90 
##  2  2  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)
##   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 }}