Home > Software engineering >  sorting date column in a dataframe in r
sorting date column in a dataframe in r

Time:09-27

I have a dataframe which looks like this

Date           Temp_value
01.03.2020       100
09.03.2020       10
05.03.2020       111
08.03.2020       112
31.12.2019       135

The date column is not sorted.

I want to sort it in an ascending order for further processing

Code I used that didnot work:

df[order(as.Date(df$date, format="%d.%m.%Y")),]

Can anyone help me with an alternative

CodePudding user response:

df$Date <- as.POSIXct(df$Date, format="%d.%m.%Y")
df= arrange(df,Date)
  • Related