Search code examples
rdatetimexlsxposixctposixlt

Reading a string column in xlsx with date and time values


I am reading a .xlsx file using R. One of the columns is called "Date" and it has the following format: "20/10/2014 12:00:00 am".

However, when I read the file using R's xlsx package, the value becomes 41932-- class factor. How can I read the entire column as a string (as is)? I want to be the one to convert the date/time values into POSIXlt and/or POSIXct classes.


Solution

  • You can read into string with Hadley's readxl package.

    library(readxl)
    df <- read_excel('~/Desktop/test.xlsx')
    

    There is some support for col_type but it's not ready yet. Instead, you can use as.POSIXct to fix those after being read into a data.frame

    e.g.

    as.POSIXct(df$Date, format="%d/%m/%Y %H:%M:%S", tz="CET")