Hi:
dat <- structure(list(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48), Self_control = c(65, 70, 60, 60, 60, 55, 60,
55, 70, 65, 60, 70, 65, 60, 60, 50, 55, 65, 70, 55, 55, 60, 50,
50, 50, 55, 80, 65, 70, 75, 75, 65, 45, 60, 85, 65, 70, 70, 80,
60, 30, 30, 30, 55, 35, 20, 45, 40), Sex = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("Female",
"Male"), class = "factor"), Alcohol = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), levels = c("None",
"2 Pints", "4 Pints"), class = "factor")), row.names = c(NA,
48L), class = "data.frame")
# Factor:
dat$Sex <- factor(dat$Sex, levels=c("Male", "Female"),
labels=c("Male", "Female"))
dat$Sex <- relevel(dat$Sex, ref="Female")
levels(dat$Sex)
I want to see how this factor is encoded, probably Female = 1 and Male = 2. How to change it to Female = 0 and Male = 1 ?
Level Encoding
1 Female 0
2 Male 1