最重要的是,我正在寻找一种快速(呃)方式对矩阵进行子集化/索引很多次:
for (i in 1:99000) {
subset.data <- data[index[, i], ]
}
Run Code Online (Sandbox Code Playgroud)
背景:
我正在实现一个涉及R中引导程序的顺序测试程序.想要复制一些模拟结果,我遇到了需要完成大量索引的瓶颈.为了实现块引导,我创建了一个索引矩阵,我用它来对原始数据矩阵进行子集以绘制数据的重采样.
# The basic setup
B <- 1000 # no. of bootstrap replications
n <- 250 # no. of observations
m <- 100 # no. of models/data series
# Create index matrix with B columns and n rows.
# Each column represents a resampling of the data.
# (actually block resamples, but doesn't matter here).
boot.index <- matrix(sample(1:n, n * B, replace=T), nrow=n, ncol=B)
# Make matrix …Run Code Online (Sandbox Code Playgroud)