Sorting data frame based on month-year time format

后端 未结 6 2113
孤城傲影
孤城傲影 2021-01-03 06:29

I\'m struggling with something very basic: sorting a data frame based on a time format (month-year, or, “%B-%y” in this case). My goal is to calculate various monthly statis

6条回答
  •  生来不讨喜
    2021-01-03 06:50

    You could reorder factor levels by reorder function.

    tmp09$monthYear <- reorder(tmp09$monthYear, as.numeric(as.Date(tmp09$ExitTime)))
    

    Trick is to use numeric representation of date as number of days since 1970-01-01 (see ?Date) and use mean value of it as reference.

提交回复
热议问题