Assigning categorical values to dates
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.parsons at gmail.com> wrote:
tibble(dates = c(rep("2021-07-04", 2), rep("2021-07-25", 3),
rep("2021-07-18", 4)))