I have these columns in my dataframe, df
:
library(readr)
library(dplyr)
library(lubridate)
year month day hour minute datetime
2013 1 7 21 54 2013-01-07 21:54:00
2013 3 20 13 59 2013-03-20 13:59:00
2013 1 3 18 40 2013-01-03 18:40:00
$ year : num [1:30115] 2013 2013 2013 2013 2013 ...
$ month : num [1:30115] 1 3 1 12 2 5 10 5 10 1 ...
$ day : num [1:30115] 7 20 3 16 24 26 30 15 31 15 ...
$ hour : num [1:30115] 21 13 18 13 21 8 13 7 12 13 ...
...
$ datetime : POSIXct[1:30115], format: "2013-01-07 21:54:00" "2013-03-20 13:59:00" "2013-01-03 18:40:00" "2013-12-16 13:29:00" ...
I have created the datetime column with this:
dfl$datetime <- with(df, as.POSIXct(paste(year, month, day, hour, minute),
format = "%Y %m %d %H %M"))
so I do not understand why when I use arrange() next
df %>% arrange(desc(datetime))
it does not sort my dataframe by datetime? I am getting
year month day hour minute date_time
<dbl> <dbl> <dbl> <dbl> <dbl> <dttm>
1 2013 1 7 21 54 2013-01-07 21:54:00
2 2013 3 20 13 59 2013-03-20 13:59:00
3 2013 1 3 18 40 2013-01-03 18:40:00
while it should be
2013-03-20 13:59:00
2013-01-07 21:54:00
2013-01-03 18:40:00