AI/R Basic
빈도분석 표와 백분율 구하기
JAYNUX
2016. 8. 21. 22:42
빈도분석 표와 백분율 구하기
descr package
질적 자료의 빈도와 백분율을 구하고 싶을 때, 유용한 함수로는 descr 패키지에 있는 freq()가 있다.
# 사용법 : freq(질적 자료)
# 예제 데이터 : InsectSprays
> attach(InsectSprays)
>install.packages("descr")
>library(descr)...
# 빈도표 작성하기 : 빈도와 백분율을 한번에 구해 준다.
> freq(spray)
# 빈도표와 막대그래프 작성하기
> freq(spray, plot=TRUE)
plyr package
install.packages('plyr')
Then, call its library, and the count() function will be ready for use.
> library(plyr)
> count(mtcars, 'gear')
gear freq
1 3 15
2 4 12
3 5 5
> y = count(mtcars, 'gear')
> y
gear freq
1 3 15
2 4 12
3 5 5
> class(y)
[1] "data.frame"
정렬하기
plyr
페키지의 arrange
를 사용
> library(plyr)
> arrange(v123, v1, desc(v2), v3)
v1 v2 v3
1 30 6500 B
2 40 5100 A
3 40 4500 A
4 50 3000 B
5 50 2000 A
6 50 2000 B
7 90 9000 A