[R] Printing a variable in a loop

kat_the_great knv4 at hotmail.com
Thu Jun 28 02:22:36 CEST 2012


Dear R Users:

I'm a STATA user converting to R, and I'd like to be to do the following. 
#Assign var_1 and var_2 a value
10->var1
20->var2

#Now I'd like to print the values of var_1 and var_2 by looping through
var_1 and var_2 in such a manner:

while(y<3){
  print(var_y)
y+1->y
}

In STATA, the "y" appended to " var_" is called the local variable and the
code would look like this:

while y<3 (
display var`y'
y=y+1
)

Stata would understand that `y' is first 1 and then 2, and print out the
values assigned to var_1 and var_2. Is there a way to do this in R? How
would R users fram this questions even? What terminology would you use?

Thanks!


--
View this message in context: http://r.789695.n4.nabble.com/Printing-a-variable-in-a-loop-tp4634673.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list