3

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.

EFL
  • 938
  • 4
  • 11
  • 23
  • Please make a reproducible question if you really want help. Have a look of your answer is here, http://www.inside-r.org/packages/cran/xlsx/docs/read.xlsx and check this link for how to ask a good question: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – MichaelVE May 11 '15 at 02:18
  • Using the `XLConnect` package addresses the issue. The column is read as it is as a string and is not converted into a number. – EFL May 11 '15 at 03:05

1 Answers1

1

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")
Maiasaura
  • 32,226
  • 27
  • 104
  • 108