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

 
(사용자 2명의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;R table()
;R table()
{{소스헤더|벡터}}
 
<source lang='r' run>
==벡터==
<syntaxhighlight lang='r' run>
x <- c(3,1,4,1,5,2,6,5)
x <- c(3,1,4,1,5,2,6,5)
table(x)
table(x)
</source>
</syntaxhighlight>
<source lang='r' run>
<syntaxhighlight lang='r' run>
table( c(3,1,4,1,5,2,6,5) )
table( c(3,1,4,1,5,2,6,5) )
</source>
</syntaxhighlight>
<syntaxhighlight lang='r' run>
table( c("a","b","b","c","c","c","d") )
</syntaxhighlight>


{{소스헤더|데이터프레임$컬럼}}
==데이터프레임 컬럼==
<source lang='r' run>
<syntaxhighlight lang='r' notebook>
table(iris$Species)
table(iris$Species)
</source>
</syntaxhighlight>
<source lang='r' run>
<syntaxhighlight lang='r' notebook>
v <- c(1, 'hello', 1, 'world', 'hello')
v <- c(1, 'hello', 1, 'world', 'hello')
table(v)
table(v)
</source>
</syntaxhighlight>
<source lang='r' run>
<syntaxhighlight lang='r' notebook>
options(echo=T)
summary(warpbreaks)
summary(warpbreaks)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
table(warpbreaks$wool,warpbreaks$tension)
table(warpbreaks$wool,warpbreaks$tension)
</source>
</syntaxhighlight>
<source lang='r' run>
<syntaxhighlight lang='r' notebook>
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Class  Name variable value
Class  Name variable value
33번째 줄: 38번째 줄:
     B  Dave    Math    90
     B  Dave    Math    90
")
")
options(echo=T)
table( scores$variable )
table( scores$variable )
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
table( scores$value )
table( scores$value )
</source>
</syntaxhighlight>


{{소스헤더|table()과 ddply()}}
==table()과 ddply()==
<source lang='r' run>
<syntaxhighlight lang='r' notebook=3>
options(echo=T)
library(plyr)
library(plyr)
table(baseball[1:100,]$year)
table(baseball[1:100,]$year)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook=3>
ddply(baseball[1:100,], ~year, nrow)
ddply(baseball[1:100,], ~year, nrow)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook=3>
ddply(baseball[1:100,], 'year', nrow)
ddply(baseball[1:100,], 'year', nrow)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook=3>
ddply(baseball[1:100,], .(year), nrow)
ddply(baseball[1:100,], .(year), nrow)
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
{{z컬럼3|
{{z컬럼3|
* [[R 분할표]]
* [[R xtabs()]]
* [[R xtabs()]]
* [[R ddply()]]
* [[R ddply()]]
63번째 줄: 73번째 줄:
* [[R addmargins()]]
* [[R addmargins()]]
* [[R margin.table()]]
* [[R margin.table()]]
* [[R 분할표]]
* [[R 그룹별 건수 구하기]]
* [[함수 array_count_values()]]
* [[함수 array_count_values()]]
}}
}}

2021년 10월 26일 (화) 19:38 기준 최신판

1 개요[ | ]

R table()

2 벡터[ | ]

x <- c(3,1,4,1,5,2,6,5)
table(x)
table( c(3,1,4,1,5,2,6,5) )
table( c("a","b","b","c","c","c","d") )

3 데이터프레임 컬럼[ | ]

table(iris$Species)
v <- c(1, 'hello', 1, 'world', 'hello')
table(v)
summary(warpbreaks)
table(warpbreaks$wool,warpbreaks$tension)
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
")
table( scores$variable )
table( scores$value )

4 table()과 ddply()[ | ]

library(plyr)
table(baseball[1:100,]$year)
ddply(baseball[1:100,], ~year, nrow)
ddply(baseball[1:100,], 'year', nrow)
ddply(baseball[1:100,], .(year), nrow)

5 같이 보기[ | ]

6 참고[ | ]

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