I have a column in my dataframe where gender is coded 1 and 0 for male and female respectively. It's not a replica, but looks something like this:
df <- read.csv("df.csv")
" Gender Age Width
1 0 35 1.4
2 0 30 1.4
3 1 32 1.3
4 1 31 1.5
5 0 36 1.4
6 1 39 1.7 "
I've managed to change the class type of it to factor and gave it labels:
df$Gender <- as.factor(df$Gender)
class(df$Gender)
df$Gender <- factor(df$Gender,
levels = c("1","0"),
labels = c("male", "female"))
However, when I try to print df$Gender, I get all "NA" as my output
UPDATE: Thank you all for your help! I realised that my code works when I run it the first time. It only becomes "NA" when I rerun the second chunk. Will this be a problem or can I just ignore it?