Earliest Date for each id in R

前端 未结 4 1690
余生分开走
余生分开走 2020-12-31 18:54

I have a dataset where each individual (id) has an e_date, and since each individual could have more than one e_date, I\'m trying to get the earli

4条回答
  •  礼貌的吻别
    2020-12-31 19:28

    I made a reproducible example, supposing that you grouped some dates by which quarter they were in.

    library(lubridate)
    library(dplyr)
    rand_weeks <- now() + weeks(sample(100))
    which_quarter <- quarter(rand_weeks)
    df <- data.frame(rand_weeks, which_quarter)
    
    df %>%
      group_by(which_quarter) %>% summarise(sort(rand_weeks)[1])
    
    # A tibble: 4 x 2
      which_quarter sort(rand_weeks)[1]
                            

提交回复
热议问题