Skip to main content
added 6 characters in body
Source Link
Rob Hyndman
  • 58.3k
  • 29
  • 148
  • 199

I wonder if there is a simple way to produce a list of variables using a for loop, and give its value.

for(i in 1:3) { noquote(paste("a",i,sep=""))=i }

for(i in 1:3)
{
  noquote(paste("a",i,sep=""))=i
}

In the above code, I try to create a1a1, a2a2, a3a3, which assign to the values of 1, 2, 3. However, R gives an error message. Thanks for your help.

Han

I wonder if there is a simple way to produce a list of variables using a for loop, and give its value.

for(i in 1:3) { noquote(paste("a",i,sep=""))=i }

In the above code, I try to create a1, a2, a3, which assign to the values of 1, 2, 3. However, R gives an error message. Thanks for your help.

Han

I wonder if there is a simple way to produce a list of variables using a for loop, and give its value.

for(i in 1:3)
{
  noquote(paste("a",i,sep=""))=i
}

In the above code, I try to create a1, a2, a3, which assign to the values of 1, 2, 3. However, R gives an error message. Thanks for your help.

Tweeted twitter.com/#!/StackStats/status/69963301781643264
Source Link
Han Lin Shang
  • 321
  • 1
  • 4
  • 3

Produce a list of variable name in a for loop, then assign values to them

I wonder if there is a simple way to produce a list of variables using a for loop, and give its value.

for(i in 1:3) { noquote(paste("a",i,sep=""))=i }

In the above code, I try to create a1, a2, a3, which assign to the values of 1, 2, 3. However, R gives an error message. Thanks for your help.

Han