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
>
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
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
3 matches
Mail list logo