Return date range by group
问题 I want to group by color and calculate the date range for that color. I have tried group_by() , summarize() and aggregate() . #Data: df1 <- as.Date(c('Jul 1', 'Jun 26', 'July 5', 'July 15'), format = '%B %d') df2 <- c("red", "blue", "red", "blue") df1 <- data.frame(df1,df2) What I'm trying to get: # Group.1 x [1] 4 red [2] 19 blue I have been trying this: df <- aggregate(df1[,1], list(df1[,2]), as.numeric(max(df1[,1]) - min(df1[,1]), units="days")) I have tested as.numeric(max(df1[,1]) - min