Given I have the column x
head(daily_negative_PRscore$x)
"2018-01-02 10:29:00 CET" "2017-01-03 18:28:00 CET" "2017-01-03 19:29:00 CET" "2018-01-03 00:00:00 CET" "2017-01-04 10:47:00 CET" "2017-01-04 11:05:00 CET"
And the way I would it to descend ideally is in the following manner:
2017-01-03 18:28:00 2017-01-03 19:29:00 2017-01-04 00:00:00 ...
CodePudding user response:
Another option is to use arrange
:
library(tidyverse)
daily_negative_PRscore %>%
arrange(desc(as.POSIXct(x)))
Or another base R option with as.Date
:
daily_negative_PRscore[rev(order(as.Date(daily_negative_PRscore$x, format = "%Y-%m-%d %H:%M:%S"))),]
Output
x
1 2018-01-03 00:00:00 CET
2 2018-01-02 10:29:00 CET
3 2017-01-04 11:05:00 CET
4 2017-01-04 10:47:00 CET
5 2017-01-03 19:29:00 CET
6 2017-01-03 18:28:00 CET
Data
daily_negative_PRscore <- structure(list(x = c("2018-01-02 10:29:00 CET", "2017-01-03 18:28:00 CET",
"2017-01-03 19:29:00 CET", "2018-01-03 00:00:00 CET", "2017-01-04 10:47:00 CET",
"2017-01-04 11:05:00 CET")), class = "data.frame", row.names = c(NA,
-6L))