0

I know that it is possible to create a variable by values. A e.g. is described here and here. Now I want to know is it possible to create in a similar way the member variable from list a by the value of x?

 x<-"name"
 a<-list( [here should place the value of x to declare the variable "name"]=1:5)

I dont searching for a workaround like changing dimnames after initialisation, because I like to do it with an S4 object initialisation.

Community
  • 1
  • 1
Klaus
  • 1,946
  • 3
  • 19
  • 34

1 Answers1

0

I think you need this one:

    x<-"name"  
    a<-list()  
    a[[x]] <- 1:5

result

    > a  
    $name  
    [1] 1 2 3 4 5
SHAI
  • 1