[R] Simple question, I think

Kevin E. Thorpe kevin.thorpe at utoronto.ca
Thu Oct 22 18:48:57 CEST 2009


David Kaplan wrote:
> Greetings,
> 
> I am recoding a dummy variable (coded 1,0) so that 0 = 2.  I am using 
> the line
> 
> sciach$dummyba[sciach$ba==0] <- 2
> 
> I notice that it creates a new column dummyba, with 0 coded as 2 but 
> with 1's now coded as NA.  Is there a simple way around this in the line 
> I am using, or do I need to have an additional line
> 
> sciach$dummyba[sciach$ba==1] <- 1
> 
> Thanks in advance.
> 
> 
> David

Try sciach$dummyba <- ifelse(sciach$ba==0,2,1)


-- 
Kevin E. Thorpe
Biostatistician/Trialist, Knowledge Translation Program
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.thorpe at utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016




More information about the R-help mailing list