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
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
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
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
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
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
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
7 matches
Mail list logo