我正在使用
我的问题是,如果观察数量增加,分位数的计算需要相当长的时间。
有没有可能通过使用
谢谢。
Hmisc
包计算两个连续变量的分位数,并在交叉表中比较结果。以下是我的代码。我的问题是,如果观察数量增加,分位数的计算需要相当长的时间。
有没有可能通过使用
data.table
、ddply
或其他任何包来加速这个过程?谢谢。
library(Hmisc)
# Set seed
set.seed(123)
# Generate some data
a <- sample(1:25, 1e7, replace=TRUE)
b <- sample(1:25, 1e7, replace=TRUE)
c <- data.frame(a,b)
# Calculate quantiles
c$a.quantile <- cut2(a, g=5)
c$b.quantile <- cut2(b, g=5)
# Output some descriptives
summaryM(a.quantile ~ b.quantile, data=c, overall=TRUE)
# Time spent for calculation:
# User System verstrichen
# 25.13 3.47 28.73
quantile()
相比,cut2()
似乎比较慢。 - majom