1

I am working with a very large dataset for which the Time and Date are two separate columns in the original excel file. I used data.table to create the dataframe and read_excel for the importing of the data into Rstudio.

The Date column imports easily as a POSIXct column, the Time column just will not display properly.

In the original excel file, the first time is "9:10". When imported to R, the program guesses that the Time column is a character column, and that "9:10" time becomes "0.38194444444444442" for reasons I do not understand. If I declare the column to be numeric, the times are still in strange decimals. If I declare the column to be a date, the time reads properly but tacks on a date I do not need, and "9:10" becomes "1899-12-31-9:10".

I have CHRON, LUBRIDATE, and ANYTIME. I have not found any functions so far that solve this issue. None of the research I've done through this site has yielded any results. Without the ability to work with time properly, I cannot continue my research. I'm sure the answer is probably very easy for most of you, but I'm fairly new to this and I'm at my wit's end!

  • Your question is good but can be made better. Include what code you've used to read the file, a sample of the data, current output and expected output. Some people find it easier to read code first. – NelsonGon Jan 20 '19 at 06:22
  • StudentFlyer, there are several good references for how to make a question reproducible, to include usable sample data and code. Top three of my picks are: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Jan 20 '19 at 06:24

1 Answers1

0

You have the correct answer, just multiply it by 24 if you want to keep the time separate or add it to the relevant date if you want date/time, and in either case format to suit.

pnuts
  • 58,317
  • 11
  • 87
  • 139