Re: [R] Replace column values in R conditional on values from different column

2012-10-13 Thread Pieter Schoonees
Or have a look at tapply(). > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Pascal Oettli > Sent: Saturday, October 13, 2012 22:16 > To: GradStudentDD > Cc: r-help@r-project.org > Subject: Re: [R] Repla

Re: [R] Replace column values in R conditional on values from different column

2012-10-13 Thread GradStudentDD
Thank you so much!!! This is exactly what I needed!! Have a wonderful rest of the weekend!! -- View this message in context: http://r.789695.n4.nabble.com/Replace-column-values-in-R-conditional-on-values-from-different-column-tp4646087p4646091.html Sent from the R help mailing list archive at N

Re: [R] Replace column values in R conditional on values from different column

2012-10-13 Thread arun
HI, Not sure how your dataset looks like and not very clear whether this is what you want. Try this: set.seed(1) Health1<-data.frame(q_5=sample(1:2,10,replace=TRUE),CohenSum=rnorm(10,25)) Health2<-data.frame(Health1,CohenM=NA,CohenF=NA) idxM<-which(Health2$q_5==1)  idxF<-which(Health2$q_5==2) H

Re: [R] Replace column values in R conditional on values from different column

2012-10-13 Thread Pascal Oettli
Hello, No need for a loop. "else if" doesn't exist in R. And Health2$CohenM and Health2_CohenF have to be created first, in case of a loop If Health2$q_5a only have 1 and 2 as possible values, just use "which" and "-". And I would suggest to not add new variables in your data frame, because