我正在使用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