갈루아의 반서재

Too Many Levels

레벨이 많은 변수는 레벨을 줄이거나 아니면 아예 해당 변수를 배제할 필요가 있다.

factors <- which(sapply(ds[vars], is.factor))

// factor : 범주형 변수로 여러개의 level로 구성

// is.factor : 주어진 자료가 factor이면 TRUE, 그렇지않으면 FALSE 반환

lvls <- sapply(factors, function(x) length(levels(ds[[x]])))

//  level : factor에 포함된 카테고리의 목록

>  (many <- names(which(lvls > 20)))

## character(0)

ignore <- union(ignore, many)

Constants 

상수값을 가진 변수 배제

(constants <- names(which(sapply(ds[vars], function(x) all(x == x[1L])))))

## [1] "location"

ignore <- union(ignore, constants)