I have a data frame DF with one of the columns being date/Time and I would like to order the data frame in descending order of this column.
DF <- data.frame(ID=c('ID3', 'ID2','ID1'), end=c('4/1/10 12:00', '6/1/11 14:20', '1/1/09 11:10'), age=c(40,30,20));
I first converted the end
column into et
using et = as.POSIXct(DF$end,format='%m/%d/%Y %H:%M')
, and used the following, but got the error that unary operator '-' is not accepted for the argument :
out <- DF[order(-DF$et),];
I also tried used the descending flag but again got an error about arguments not being of same length.
out <- DF[order(DF$et, descending=TRUE),];
However, the ascending order seems to work: out <- DF[order(DF$et),]
.
How can I order in descending order (most recent time first)? Thank you.