date_df <- tibble(dates = c(rep("2021-07-04", 2), rep("2021-07-25", 3), rep("2021-07-18", 4)))
cycle_from_date <- function(date,dates){ dates |> unique() |> sort() -> ranks match(date,ranks) } date_df |> mutate(cycle_new=cycle_from_date(dates,dates)) > On 22.07.2021, at 05:46, N. F. Parsons <nathan.f.pars...@gmail.com> wrote: > >>> tibble(dates = c(rep("2021-07-04", 2), rep("2021-07-25", 3), >>> rep("2021-07-18", 4))) ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.