dplyr count observations per day

前端 未结 1 1761
既然无缘
既然无缘 2021-01-25 09:37

I have the following data

Name         Date                                   Message
Ted Foe      2011-06-10T05:06:30+0000               I love this product
Sin         


        
相关标签:
1条回答
  • 2021-01-25 09:58

    Grouped by the 'Date' column after converting to Date class, we get the number of rows (n()) with summarise. If we need the 'Date' elements that are missing in the original dataset, create a new dataset with the sequence of minimum to maximum 'Date' and do a left_join

    df1 <- df %>%
              group_by(Date = as.Date(Date)) %>%
              summarise(comments = n())
    expand.grid(Date = seq(min(df1$Date), max(df1$Date), by = '1 day')) %>%
             left_join(., df1)
    
    0 讨论(0)
提交回复
热议问题