I am building an agegroup variable. if later when I make table, and I want all categories to show, should I make it a factor? How whould I do it.
My codes are:
df<-df %>%
mutate(AGEGROUP =cut (AGE,
breaks=c(-Inf,0,0.001, 0.082,1.99,12.999,64.999,200),
right=TRUE,
labels = c("Foetus(0 yr)",
"Neonate (0.001 - 0.082 yr)",
"Infant(0.083-1.999 yrs)",
"Child(2-12.999 yrs)",
"Adolescent(13-17.999 yrs)",
"Adult(18-64.999 yrs.)",
"Elderly(65-199 yrs)")
))
df<-df %>%
group_by(AGEGROUP) %>%
summarise("peopel count" = n())
Right now, if i only have people in two catergories, it only show two, like
I want to have sth that looks like this: