Search code examples
rdatedataframetype-conversionr-factor

how to convert factor column into date in data frame in r


I have a data frame in r with the following structure:

TERMINAL_ID ACTION_DATE ACC_AMOUNT
1009162   02-JAN-18      14.30
1009162   02-JAN-18      21.45

and the class for 'action_date' is factor and I would to convert it to date. I tried this code but no success

dataf <- as.Date(as.character(data$ACTION_DATE),
                                format = "%d-%y-%Y")
fdate=as.POSIXlt(data$ACTION_DATE, "%d-%b-%y")

Solution

  • as.Date('02-JAN-18', format = '%d-%B-%y')
    
    [1] "2018-01-02"