创建一个数字序列块 - R

Create a block of a sequence of numbers - R

我想创建一个块,即 R 中数字序列的不可变数字列表。 意思是当我索引列表时,我会得到这组数字。

ts <- cbind(1:11, 12:22, 23:33, 34:44, 45:55, 56:66, 67:77, 78:88, 89:99, 100:110, 111:121)
#divide numbers in 11 groups
sample(a, 11, replace=TRUE)
#should "shuffle" the blocks so that I have for example (12:22, 34:44, 45:55, 56:66, 56:66, 34:44, etc.)
ts[3]
[23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]

这将用于bootstrap。其余的代码已经设置好了,下面我将post作为参考。

for (j in 1:10){
    s <- NULL
    #ts is the above sequence
    s <- sample(ts, 11, replace = TRUE)
    a3 <- Three_grosslarger2[s,]
    x <- factors[s,]

    for (i in 1:length(Four_grosslarger2)){
            m_a3 <- summary(lm(a3[,i] - x[,4] ~ x[,1] + x[,2] + x[,3] + x[,5], na.action = na.exclude), data = a3)
            Four_grosslarger2_a[j, i] <- m_a3$coefficients[1,1]
            Four_grosslarger2_ta[j, i] <- m_a3$coefficients[1,3]

谢谢!

如果将结构更改为列表

ts <- list(c(1:11), c(12:22), c(23:33), c(34:44), c(45:55), c(56:66), c(67:77), c(78:88), c(89:99), c(100:110), c(111:121))
#divide numbers in 11 groups
sample(ts, 11, replace=TRUE)
#should "shuffle" the blocks so that I have for example (12:22, 34:44, 45:55, 56:66, 56:66, 34:44, etc.)