0

I have an xlsx file with a number of variables (columns). Quite a few are listed in date format (MM/DD YYYY HH:MM A/P) in the .xlsx file. When I load this file into R using read.xlsx, all of the variables with date format load as POSIXct except ONE, which always loads as a factor variable. Any thoughts on why this may be?

For reference I am loading the data using code similar to that below:

data <- read.xlsx("file.xlsx", sheetIndex = 1, header = TRUE)
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
Ben
  • 53
  • 4
  • `MM/DD YYYY HH:MM A/P` is not a data-time format that would be read by as.POSIXct unless provided with a format spec. Your solution suggests that you were reporting the format that you see in an Excel window which is not how Excel (or R for that matter) stores date-times. – IRTFM Mar 06 '15 at 02:51

1 Answers1

0

Well, I figured it out! Turns out one of the entries for this variable (of the hundreds) was entered slightly incorrectly in the xlsx file (it was listed as 15:00 PM, an impossible time!), which threw off the xlsx package I suppose. Once fixed, the data pull results in a column with POSIXct entries.

Hope this helps anyone else in the future encountering a similar problem!

Ben
  • 53
  • 4