对于10万行,它花费5秒。实在是太多了。您是否知道如何改进此代码以更快地进行检查?
AuthServiceProvider.php
答案 0 :(得分:1)
我们可以使用tabulate
来提高速度
check <- function(xVar, sen){
if (min(tabulate(xVar)) < sen){
warn <- "Variable has very low number in some branches - IV can be spoiled"
}else{
warn <- ""
}
}
start <- Sys.time()
check(xVar, sen)
stop <- Sys.time()
stop - start
#Time difference of 0.272254 secs
使用OP的功能,stop
和start
的差异为
stop - start
#Time difference of 5.077512 secs
set.seed(24)
xVar <- as.factor(sample(x=c("transp","bud","wolny","pref",
"inny"), size=100000000, replace=T))
sen <- 10000