Home > other >  How to order years by month?
How to order years by month?

Time:11-22

Assuming:

     s1=seq(as.Date("1950/01/01"), by = "month", length.out = 200)

Will give:

     1950-01-01
     1950-02-01
     1950-03-01
     1950-04-01

this is one comuln in a dataframe, I would like to arragne the whole datafram:

   1950-01-01
   1951-01-01
   1952-01-01
   1953-01-01

CodePudding user response:

s1[order(lubridate::month(s1))]

or to order by month and by year

s1[order(lubridate::month(s1), lubridate::year(s1))]

in a data.frame

df[order(lubridate::month(df$s1), lubridate::year(df$s1)), ]
  •  Tags:  
  • r
  • Related