Hi everybody!

I have a rather simple question:

# play data
persId<-c(1,2,3,1,4,5,2)
varA<-c(11,12,13,12,14,15,10)
df<-as.data.frame(cbind(persId, varA))

Now I'd like to create a new columns (df$new)
according to the value of df$VarA. For  example
df$new1 should be 1 if df$varA==2 or df$new2 should
be 1 if df$varA>13.

I tried to do it like this:

if(df$varA==2) {df$new1<-1}

But, obviously, that's not how it works (I might be thinking to much in
mySQL: update table set new1=1 where varA==2).

How can I solve this problem using "if"?
I would not want to use recode() as my conditions might be more complicated
later on.

Thank you very much!
David

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to