Re: [R] Printing a variable in a loop

2012-06-28 Thread Petr PIKAL
Hi > > Thanks for your reply Jon. > > I need to actually do more than print the name of the variable (I just made > the example simpler). I need to manipulate var_1, var_2 etc. but setting > values of NA to 0. Why? R has pretty strong system for handling NAs. The only exception AFAIK is cums

Re: [R] Printing a variable in a loop

2012-06-28 Thread Rui Barradas
Hello, Try the following. dd <- data.frame(A=letters[1:10], var_1=1:10, var_2=11:20) index <- grep("var_", names(dd)) for(i in index) print(dd[[ i ]]) # or dd[, i] # vars <- paste("var", 1:2, sep="_") for(v in vars) print(dd[, v]) # or dd[[ v ]] There's nothing you can do i

Re: [R] Printing a variable in a loop

2012-06-28 Thread kat_the_great
Hi Oliver, Thank you for your reply. I can't use vectors as each var_1, var_2 is a new column/variable, not a new observation within a vector. But thank you, Kat -- View this message in context: http://r.789695.n4.nabble.com/Printing-a-variable-in-a-loop-tp4634673p4634756.html Sent from the

Re: [R] Printing a variable in a loop

2012-06-28 Thread kat_the_great
Thanks for your reply Jon. I need to actually do more than print the name of the variable (I just made the example simpler). I need to manipulate var_1, var_2 etc. but setting values of NA to 0. So as you said, "1. if you want to "display" the variable, just type it >var_1 " But how do I do

Re: [R] Printing a variable in a loop

2012-06-28 Thread Oliver Ruebenacker
Hello, Can't you just use vectors? Untested example: var[1] <- 10 var[2] <- 20 y <- 1 while(y < 3) { print(var[y]) y <- y+1 } Take care Oliver On Wed, Jun 27, 2012 at 8:22 PM, kat_the_great wrote: > Dear R Users: > > I'm a STATA user converting to R, and I'd

Re: [R] Printing a variable in a loop

2012-06-27 Thread Miguel Manese
Hi Kat, On Thu, Jun 28, 2012 at 8:22 AM, kat_the_great wrote: > 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 a

[R] Printing a variable in a loop

2012-06-27 Thread kat_the_great
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