Skip to content
Prev 394344 / 398500 Next

Recombining Mon and Year values

An alternative that does not use the zoo package but uses the built-in
constant month.abb

df1 <- data.frame(Year = c(2021, 2021, 2021),
                   Mon = c("Mar", "Jan", "Apr"))

df1$mon_year <- df1$Year*100 + sapply(df1$Mon, \(x) match(x,month.abb))

sort(df1$mon_year)
On Wed, May 17, 2023 at 2:48?AM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: