如何为R中的多个变量分配列表? [重复]

时间:2023-01-31 15:12:09

This question already has an answer here:

这个问题在这里已有答案:

If I for example have a list of values respectively for simplicity: (1, 2, 3, 4, 5, 6, 7, 8), how can I assign each of those to variables A through H, where A = 1, B = 2, C = 3, D = 4 , ... H = 8, each letter matching the value at the corresponding index in the list?

例如,如果我为了简单而分别有一个值列表:(1,2,3,4,5,6,7,8),我怎样才能将每个值分配给变量A到H,其中A = 1,B = 2,C = 3,D = 4,...... H = 8,每个字母是否与列表中相应索引的值相匹配?

I was hoping that (LETTERS[1:8]) = c(1, 2, 3, 4, 5, 6, 7, 8) would work, but it does not?

我希望(LETTERS [1:8])= c(1,2,3,4,5,6,7,8)可行,但事实并非如此?

1 个解决方案

#1


2  

   ar<-array(c(letters[1:26]), dim = c(1,26))
     for(i in 1:26) {
     assign(eval(ar[i]),i )
     }
    print(c)

Something like that?

那样的东西?

#1


2  

   ar<-array(c(letters[1:26]), dim = c(1,26))
     for(i in 1:26) {
     assign(eval(ar[i]),i )
     }
    print(c)

Something like that?

那样的东西?