[R] Several factors same levels

From: dereksloan <djsloan_at_liv.ac.uk>
Date: Tue, 19 Apr 2011 01:57:25 -0700 (PDT)


This is probably very simple but I'm new to R so apologies for being stupid.

I have some data with No coded as 0 and yes coded as 1.

e.g.

id sex alcohol smoker

1   M     0        1
2   F      1        0 
3   M     0        0 

I realise I can covert the numerical variable back to a factor by

falcohol<-factor(alcohol,levels=0:1)
levels<-c("No","Yes")
fsmoker<-factor(smoker,levels=0:1)
levels<-c("No","Yes")

but can I do this for all factors using the same levels in a single command to make it easier (i.e. switch all 0/1, no/yes variables without having to recode the same factor levels for them all)?

Derek

--
View this message in context: http://r.789695.n4.nabble.com/Several-factors-same-levels-tp3459878p3459878.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_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.
Received on Tue 19 Apr 2011 - 11:49:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 12:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive