0

For my dataset, the Date variable has dates in the format of this example: 19-Feb-03 I want to change the above character format dates in the column to a Date format. (As I have to do time series analysis later on)

I tried using the as.Date() method but it didn't work.

  • 1
    You can use `lubridate::dmy()` or you can specify a format string (assuming your locale is English) `as.Date(your_data$your_column, format = "%d-%b-%y")`. The format string keys are documented at `?strftime`. – Gregor Thomas Dec 01 '22 at 14:30

2 Answers2

1
x <- '19-Feb-03'

lubridate::ymd(x)

"2019-02-03"
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
1

Not sure whether 19 is year or day. You can try lubridate package

x<-"19-Feb-03"

library(lubridate)

ymd(x)
dmy(x)

chris jude
  • 467
  • 3
  • 8