[Solved] Summarize data.frame by dates in R


I would use data.table and do something like the following:

library(data.table)
setDT(df)
ndf <- df[, 
          .(Date = paste(Date[1], "to", Date[.N]), weather = Type.of.Weather[1]),
          rleid(Type.of.Weather)
          ][,
            rleid := NULL
           ][]
ndf
               Date weather
1: 01-Jan to 03-Jan  Cloudy
2: 04-Jan to 10-Jan   Rainy
3: 11-Jan to 15-Jan  Cloudy
4: 16-Jan to 20-Jan   Sunny

1

solved Summarize data.frame by dates in R