Aggregate with max and factors
问题 I have a data.frame with columns of factors, on which I want to compute a max (or min, or quantiles). I can't use these functions on factors, but I want to. Here's some example : set.seed(3) df1 <- data.frame(id = rep(1:5,each=2),height=sample(c("low","medium","high"),size = 10,replace=TRUE)) df1$height <- factor(df1$height,c("low","medium","high")) df1$height_num <- as.numeric(df1$height) # > df1 # id height height_num # 1 1 low 1 # 2 1 high 3 # 3 2 medium 2 # 4 2 low 1 # 5 3 medium 2 # 6 3