1. 도수 분포표
df <- read.csv("testdata/ex_studentlist.csv")
head(df,3)
# name gender age grade absence bloodtype height weight
# 1 김길동 남 23 3 유 O 175.3 68.2
# 2 이미린 여 NA 2 무 AB 170.1 53.0
# 3 홍길동 남 24 4 무 B 175.0 80.1
2. 범주형 자료(bloodtype)로 분할표
freq <- table(df$bloodtype)
freq
# A AB B O
# 3 3 4 5
3. 상대 도수 (전체 합 = 1)
rfreq <- prop.table(freq)
rfreq
# A AB B O
# 0.2000000 0.2000000 0.2666667 0.3333333
rtable <- rbind(freq, rfreq)
rtable <- addmargins(rtable, margin = 1) # 열에 소계 더하기
# A AB B O
# freq 3.0 3.0 4.0000000 5.0000000
# rfreq 0.2 0.2 0.2666667 0.3333333
# Sum 3.2 3.2 4.2666667 5.3333333
rtable <- addmargins(rtable, margin = 2) # 행에 소계 더하기
# A AB B O Sum
# freq 3.0 3.0 4.0000000 5.0000000 15
# rfreq 0.2 0.2 0.2666667 0.3333333 1
# Sum 3.2 3.2 4.2666667 5.3333333 16
4. 연속형 자료(height)로 분할표
#연속형 자료(height)로 분할표
table(df$height)
# 155.2 162 162.2 167.1 168 170.1 175 175.3 176.1 176.9 178.2 178.5 182.1
# 1 1 1 1 1 1 1 1 2 1 1 1 1
5. 연속형 자료에 구간 설정 : cut()
factorHeight <- cut(df$height, breaks = 4) # breaks : 구간 수. (초과, ]이하
# [1] (172,180] (163,172] (172,180] (180,188] (163,172] (155,163] (155,163]
# [8] (172,180] (172,180] (172,180] (163,172] (180,188] (155,163] (172,180]
# [15] (172,180]
# Levels: (155,163] (163,172] (172,180] (180,188]
freqHeight <- table(factorHeight)
# (155,163] (163,172] (172,180] (180,188]
# 3 3 7 2
freqHeight <- rbind(freqHeight, prop.table(freqHeight))
# (155,163] (163,172] (172,180] (180,188]
# freqHeight 3.0 3.0 7.0000000 2.0000000
# 0.2 0.2 0.4666667 0.1333333
'BACK END > R' 카테고리의 다른 글
[R] R 정리 7 - 내장함수, 시각화 (0) | 2021.01.28 |
---|---|
[R] R 정리 6 - 조건문, 반복문 (0) | 2021.01.28 |
[R] R 정리 4 - 데이터 입출력 (0) | 2021.01.28 |
[R] R 정리 3 - 자료구조 (0) | 2021.01.27 |
[R] R 정리2 - 변수 (0) | 2021.01.26 |