In R , how to use the value of a variable as the name of another variable
for example:
SCE<-function(i){ #x<-paste0("SCE",i) x<-c(i,i+1) return (x) } x<-paste0("SCE",1) y<-SCE(1) paste0("SCE",1)=SCE(1) cat("SCE",1)=SCE(1) How can I make the value of variable x (string) as the name of another variable y (unknown data type)? Here, the final result I want to get is a variable named SCE1, its type is numeric, and its value is 1 2
The problem I actually encountered is: I have a repetitive code that I want to use a for loop to complete, but every time I complete it, I want to save the result as a variable so that I can use it later.
SCE<-function(i){ #x<-paste0("SCE",i) x<-c(i,i+1) return (x) } for (i in 2:9) { x<-paste0("SCE",i) y<-SCE(i) } Every time the for loop is completed, I hope to get a variable of SCE+number, whose value is the result of the corresponding SCE function
