1

I have imported an excel file into R that has a Date and Time column that I need help formatting to match m/d/yyyy h:mm AM/PM, similar to a custom date function in excel. The Date column is currently formatted as %Y-%M%-%D and is in POSIXct format when imported to R. The Time column looks similar to the following:

File$Time <- c("0:00", "0:30", "1:00", "1:30", "13:30")

I need help converting these intervals to times as such 0:00 would be 12:00 AM and 13:30 would be 1:30 PM etc. Then I need to add 4 to each time to get it into UTC time. Once that has been done I need a single column that matches the m/d/yyyy h:mm AM/PM format with the date and time from the excel file.

Thanks for any tips or help in advance!

whoosis
  • 454
  • 7
  • 25
seals
  • 11
  • 2
  • Possible duplicate of [Converting a character string into a date in R](https://stackoverflow.com/questions/32854538/converting-a-character-string-into-a-date-in-r) – divibisan Aug 08 '18 at 20:41
  • 1
    Something like `x = as.POSIXct(paste(date_col, time_col), "%m/%d/%Y %H:%M")` and then `format(x, some_other_format)`. To determine the right format strings, there's a listing in `?strptime`. – Frank Aug 08 '18 at 20:43
  • 1
    Or, if the problem is merging date and time into date.time: combine date and time into datetime: https://stackoverflow.com/questions/11609252/r-tick-data-merging-date-and-time-into-a-single-object – divibisan Aug 08 '18 at 20:43

0 Answers0