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

 
(사용자 2명의 중간 판 11개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;R table()
;R table()
{{소스헤더|벡터}}
 
<source lang='r'>
==벡터==
<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)
## x
</syntaxhighlight>
## 1 2 3 4 5 6
<syntaxhighlight lang='r' run>
## 2 1 1 1 2 1
</source>
<source lang='r'>
table( c(3,1,4,1,5,2,6,5) )
table( c(3,1,4,1,5,2,6,5) )
##
</syntaxhighlight>
## 1 2 3 4 5 6
<syntaxhighlight lang='r' run>
## 2 1 1 1 2 1
table( c("a","b","b","c","c","c","d") )
</source>
</syntaxhighlight>
{{소스헤더|데이터프레임$컬럼}}
 
<source lang='r'>
==데이터프레임 컬럼==
<syntaxhighlight lang='r' notebook>
table(iris$Species)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
v <- c(1, 'hello', 1, 'world', 'hello')
v <- c(1, 'hello', 1, 'world', 'hello')
table(v)
table(v)
## v
</syntaxhighlight>
##    1 hello world
<syntaxhighlight lang='r' notebook>
##    2    2    1
</source>
<source lang='r'>
summary(warpbreaks)
summary(warpbreaks)
##    breaks      wool  tension
</syntaxhighlight>
## Min.  :10.00  A:27  L:18 
<syntaxhighlight lang='r' notebook>
## 1st Qu.:18.25  B:27  M:18 
## Median :26.00          H:18 
## Mean  :28.15               
## 3rd Qu.:34.00               
## Max.  :70.00               
 
table(warpbreaks$wool,warpbreaks$tension)
table(warpbreaks$wool,warpbreaks$tension)
## 
</syntaxhighlight>
##  L M H
<syntaxhighlight lang='r' notebook>
## A 9 9 9
## B 9 9 9
</source>
<source lang='r'>
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
scores <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
Class  Name variable value
Class  Name variable value
49번째 줄: 38번째 줄:
     B  Dave    Math    90
     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 )
table( scores$variable )
## English    Math
</syntaxhighlight>
##      3      3
<syntaxhighlight lang='r' notebook>
table( scores$value )
</syntaxhighlight>


table( scores$value )
==table()과 ddply()==
## 60 80 90
<syntaxhighlight lang='r' notebook=3>
##  2  2  2
</source>
{{소스헤더|table()과 ddply()}}
<source lang='r'>
library(plyr)
library(plyr)
table(baseball[1:100,]$year)
table(baseball[1:100,]$year)
##
</syntaxhighlight>
## 1871 1872 1873 1874 1875 1876 1877 1878
<syntaxhighlight lang='r' notebook=3>
##    7  13  13  15  17  15  17    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)
##  year V1
</syntaxhighlight>
## 1 1871  7
## 2 1872 13
## 3 1873 13
## 4 1874 15
## 5 1875 17
## 6 1876 15
## 7 1877 17
## 8 1878  3
</source>


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[R xtabs()]]
* [[R ddply()]]
* [[R factor()]]
* [[R ftable()]]
* [[R unique()]]
* [[R is.table()]]
* [[R as.table()]]
* [[R tabulate()]]
* [[R tabulate()]]
* [[R ftable()]]
* [[R summary()]]
* [[R factor()]]
* [[R xtabs()]]
* [[R margin.table()]]
* [[R prop.table()]]
* [[R prop.table()]]
* [[R addmargins()]]
* [[R addmargins()]]
* [[R summary()]]
* [[R margin.table()]]
* [[R ddply()]]
* [[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 }}