简体   繁体   English

创建一个数字序列块 - R

[英]Create a block of a sequence of numbers - R

I would like to create a block, meaning an immutable list of numbers, of a sequence of numbers in R.我想在 R 中创建一个数字序列的块,即不可变的数字列表。 Meaning that when I index the list, I will get the group of numbers.这意味着当我索引列表时,我会得到一组数字。

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]

This will be used to bootstrap.这将用于引导。 Rest of the code is already set, which I will post for reference below.代码的Rest已经设置好了,下面贴出来供大家参考。

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]

Thank you!谢谢!

If you change the structure to a list如果将结构更改为列表

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.)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM