Description Usage Arguments Details Value See Also Examples
binning()은 수치형 데이터를 비닝하여 범주형 데이터로 변환합니다.
1 2 3 4 5 6 7 8 |
x |
numeric. 비닝의 대상이 되는 수치 벡터 |
nbins |
integer. 비닝할 빈(bin)의 개수. 필수 인수로 만약에 기술하지 않으면 nclass.Sturges의 결과가 사용됩니다. |
type |
character. 비닝 방법을 기술합니다. "quantile", "equal", "pretty", "kmeans", "bclust"에서 선택합니다. "quantile"는 동일한 분위수 구간의 브레이크포인트를 사용하여 비닝합니다. "equal"은 동일한 길이의 구간(interval)의 브레이크포인트를 사용하여 비닝합니다. "pretty"는 base::pretty() 함수를 활용하여 비닝합니다. "kmeans"는 stats::kmeans() 함수를 사용하여 k-mean 방법으로 비닝합니다. "bclust"는 e1071::bclust() 함수를 사용하여 bagged clustering 방법으로 비닝합니다. "kmeans"와 "bclust" 방법은 classInt::classIntervals() 함수를 사용하였습니다. |
ordered |
logical. 비닝된 결과를 ordered factor로 생성할지의 여부 |
labels |
character. 각 수준에 사용할 라벨 이름 |
approxy.lab |
logical. 큰 숫자의 프레이크포인트에 대해서 근사값의, 좀더 예쁜 값의 라벨을 취할지의 여부를 선택합니다. TRUE일 경우에는 근사값으로, FALSE일 경우에는 원래의 값을 라벨로 사용합니다. |
이 함수는 dplyr 패키지의 mutate, 혹은 transmute 함수와 사용하면 효율적으로 데이터를 비닝할 수 있습니다.
비닝의 이해를 위해서 vignette("transformation") 명령어로 비네트를 참고하세요.
bins 클래스 객체. bins 클래스의 속성은 다음과 같습니다.
class : "bins"
type : 비닝 방법, "quantile", "equal", "pretty", "kmeans", "bclust".
breaks : 비닝의 브레이크 포인트로, x의 간격을 정합니다.
levels : 비닝된 범주형 데이터의 수준
raw : 비닝 되기 전의 원(raw) 데이터로서의 수치 벡터
binning_by
, print.bins
,
summary.bins
, plot.bins
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # 예제를 위한 데이터 생성
heartfailure2 <- heartfailure
heartfailure2[sample(seq(NROW(heartfailure2)), 20), "platelets"] <- NA
# type 인수의 기본값인 "quantile"을 이용한 platelets 변수의 비닝
bin <- binning(heartfailure2$platelets)
# bins 클래스 객체의 출력
bin
# bins 클래스 객체의 요약
summary(bin)
# bins 클래스 객체의 시각화
plot(bin)
# labels 인수를 이용한 사례
bin <- binning(heartfailure2$platelets, nbins = 4,
labels = c("LQ1", "UQ1", "LQ3", "UQ3"))
bin
# 다른 인수를 이용한 사례들
bin <- binning(heartfailure2$platelets, nbins = 5, type = "equal")
bin
bin <- binning(heartfailure2$platelets, nbins = 5, type = "pretty")
bin
bin <- binning(heartfailure2$platelets, nbins = 5, type = "kmeans")
bin
bin <- binning(heartfailure2$platelets, nbins = 5, type = "bclust")
bin
x <- sample(1:1000, size = 50) * 12345679
bin <- binning(x)
bin
bin <- binning(x, approxy.lab = FALSE)
bin
# 비닝된 결과의 추출
extract(bin)
# ------------------------------------
# dplyr 패키지와 파이프를 이용한 사례
# ------------------------------------
library(dplyr)
# 비닝된 결과를 death_event 변수별로 돗수를 구함
heartfailure2 %>%
mutate(platelets_bin = binning(heartfailure2$platelets) %>%
extract()) %>%
group_by(death_event, platelets_bin) %>%
summarise(freq = n()) %>%
arrange(desc(freq)) %>%
head(10)
# 비닝된 결과를 death_event 변수별로 도수를 파악할 수 있는 시각화
heartfailure2 %>%
mutate(platelets_bin = binning(heartfailure2$platelets) %>%
extract()) %>%
target_by(death_event) %>%
relate(platelets_bin) %>%
plot()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.