Reputation: 1
I am coding this in r and solved this in an alternative way to make the vector to a list and assign value to each of the element of the list, but is there any other direct simple approach?
for(i in 1:5){
paste('var',i,sep='')=i
}
i want output where 1:5 will assign like
var1=1
var2=2
var3=3
var4=4
var5=5
Upvotes: 0
Views: 24
Reputation: 545905
Don’t do this. Use a vector or list instead:
var = 1 : 5
Now you can use var[1]
(instead of var1
) etc.
Your code doesn’t work because paste
creates a character vector, not a variable name.
Upvotes: 1