这是一个
R使用示例的示例
data.table,但如果不这样做
data.table也应该很容易。
# Load data.tablerequire(data.table)# Some dataset.seed(1)dt <- data.table(type = factor(sample(c("A", "B", "C"), 10e3, replace = T)), weight = rnorm(n = 10e3, mean = 70, sd = 20))# Decide the minimum frequency a level needs...min.freq <- 3350# Levels that don't meet minumum frequency (using data.table)fail.min.f <- dt[, .N, type][N < min.freq, type]# Call all these level "Other"levels(dt$type)[fail.min.f] <- "Other"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)