Re: [R] Several factors same levels

2011-04-19 Thread peter dalgaard
On Apr 19, 2011, at 10:57 , dereksloan wrote: > 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 01 > 2 F 10 > 3 M 00 >

Re: [R] Several factors same levels

2011-04-19 Thread Dimitris Rizopoulos
one way is the following: DF <- data.frame(id = 1:6, sex = gl(2, 3, labels = c("M", "F")), x = sample(0:1, 6, TRUE), y = sample(0:1, 6, TRUE), z = rnorm(6)) f <- function (x) { if (all(unique(x) %in% 0:1)) factor(x, levels = 0:1, labels = c("No", "Yes")) else

[R] Several factors same levels

2011-04-19 Thread dereksloan
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 01 2 F 10 3 M 00 I realise I can covert the numerical variable back to a factor by f