100x 循环,每次从数据帧中获取行名称并作为列添加到新数据帧 B,以 B 中的 100 列结尾

100x loop, get rownames from dataframe A and add as a column to a new dataframe B each time, ending with 100 columns in B

我想每次执行 100x , get rownames from a A and add its rownames as values in a column to a new B,以 B 中的 100 列结束。为了做到这一点,我正在用头撞墙,因为我似乎以我尝试过的每一种方式都覆盖了 B。

     data <- bs.exp.sorted.1198.input
     outsft = dataframe
     outsamps = dataframe 
     samples<- data.frame(matrix(0, nrow = 60, ncol = 1))
     currentsamps =dataframe 
     itnumb=100 

    for(i in 1:itnumb){
    subsamp <- data[sample(nrow(data), 60), ]

    powers =c(c(1:10), seq(from=12,to=20,by=2))
    sft =pickSoftThreshold(bs.exp.sorted.1198.input, powerVector = powers, verbose=5)


    outsft <- rbind(outsft, sft$fitIndices[,2])

    currentsamps <- as.data.frame(rownames(subsamp))
    output <- add_column(samples, currentsamps)

    }

输出始终包含一列 0(我必须包含它才能使其正常工作...无论循环中最后一组行名是什么。我想将所有行名保存在一个大数据框中。这应该是一个简单的任务,但它让我难住了,在这一点上,激怒了。有什么建议吗? 谢谢。

这个怎么样:

initial_rows = 100
initial_df = data.frame( col1 = rnorm( initial_rows ),  
                         row.names = 1:initial_rows )
stores_names = rownames( initial_df )

chunk_size = 10
n_repetitions = 10
result = data.frame( matrix( NA_character_, 
                             nrow = chunk_size, ncol = n_repetitions ) )

for ( i_rep in seq_len(n_repetitions) ) {

  current_names = sample( stores_names, chunk_size ) 
  result[ , i_rep ] = current_names

}

> result
   X1  X2 X3 X4 X5 X6 X7 X8 X9 X10
1  72  62 24 35 80 48  6 79 17  96
2  66   4 59 39 32 67 95 96 89  26
3  34  21 96 75 22 87  8 49 98  50
4  40  33 74 90 39  2 86 78 15   3
5  87  12 70 72 62 98 69  4  1  32
6  98  43  7 38 18 57 83 47 35  41
7  28  70  6 84 30  4 54 46  4  35
8  94 100 80 36 84  7 56 36 73   9
9  60  88 28 11 73 32  3 23 85  67
10 69  69 68 69  4 17 60 63 62  47

这是你想要的吗?