I would like to creat a var named"AGEGROUP" for age group. I wrote following code. But it seems like the new variable name in the data set show up as "... <- NULL" instead of "AGEGROUP". Why? How should I fix this.
Here is my codes:
set.seed(12345)
AGE <- sample(0:110, 100, replace = TRUE)
Sample.data <-data.frame(AGE)
Sample.data <- Sample.data %>% dplyr::mutate(AGEGROUP <-cut(AGE,
right=FALSE,
breaks = c(0,1,12,17,64,1000),
labels = c("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)")))
There seems to be a <-
(assignment) instead of "=" (parameter match):
library("dplyr")
set.seed(12345)
AGE <- sample(0:110, 100, replace = TRUE)
Sample.data <-data.frame(AGE)
Sample.data <- Sample.data %>%
dplyr::mutate(AGEGROUP = cut(
AGE,
right = FALSE,
breaks = c(0, 1, 12, 17, 64, 1000),
labels = c(
"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)"
)
))