Mayra Sáenz
Mayra Sáenz

Reputation: 13

R Factor function changes levels

I need to label a numeric variable, called sex, with "male" and "female". I was told to use de function "factor" but when I use it, it uses "1" and "2" instead of "0 " and "1". This is my code:

ucisex<−factor(ucisex<−factor(ucisex, levels = c(0:1), labels = c("male","female"))

It happens also with all the other variables when I label them. Please help!!!!

Mayra

Upvotes: 1

Views: 99

Answers (1)

akrun
akrun

Reputation: 887391

The OP' had multiple <- and factor calls, which is not needed

ucisex <- factor(ucisex, levels = 0:1, labels = c("male", "female"))
ucisex
#[1] male   male   female female female female male   female female male  
#Levels: male female

data

set.seed(24)
ucisex <- sample(0:1, 10, replace=TRUE)

Upvotes: 0

Related Questions