How to sort a data frame by date

前端 未结 7 750
孤城傲影
孤城傲影 2020-11-28 21:46

I need to sort a data frame by date in R. The dates are all in the form of \"dd/mm/yyyy\". The dates are in the 3rd column. The column header is V3. I have seen how to s

7条回答
  •  遥遥无期
    2020-11-28 22:02

    Nowadays, it is the most efficient and comfortable to use lubridate and dplyr libraries.

    lubridate contains a number of functions that make parsing dates into POSIXct or Date objects easy. Here we use dmy which automatically parses dates in Day, Month, Year formats. Once your data is in a date format, you can sort it with dplyr::arrange (or any other ordering function) as desired:

    d$V3 <- lubridate::dmy(d$V3)
    dplyr::arrange(d, V3)
    

提交回复
热议问题