r - Value label for variable -


i want attach value label variables (0 = "male" , 1 = "female") in data frame.

i tried this:

cb$gender <- factor(cb$gender, levels = c(0,1), labels = c("male", "female")) 

but result:

[1]  female male   male   male   female female male   female female male         male   male   male   male   [15] male   female female male   female female male   male   male   female       male   female male   male   [29] male   female female male 

any idea?

i don't quite know wrong splitting apart seemed work

 gender<-c("male","female","male","female")   gender <- as.factor(gender)   levels(gender)<-c(0,1) 

of course, pay attention fact used own made data.

so try subset data first

gender<-cb$gender     

and apply above. best of luck!


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -