0

I am trying to take a column of my data that is in factor format and change it to time in the format hours:minutes:seconds:milliseconds

I tried:

start.times <- as.POSIXct(as.character(start.times), format="%H:%M:%OS")

but it returned values with todays date and left out the milliseconds in them and that is not what I want. I also tried downloading chron and running the code:

start.times <- times(start.times) but this just returned NA's.....

Please help! My data is all about start times and end times of dolphin vocalizations and I am trying to find the mean whistle duration and the inter whistle interval. Anyways, I don't really know how to get my data into the format I need it in. Thank you!

  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 06 '19 at 19:04
  • 1
    Today's date will automatically be added when converting to POSIXct and you do not supply your own date. Other than that we can't helpt without example data. – JBGruber Dec 06 '19 at 19:08
  • my data ranges from values: 0:13:45.9 to 3:09:44.9. – Michaela Alksne Dec 06 '19 at 19:16
  • sample code: >0:13:45:9 <- as.POSIXct(as.character(0:13:45:9), format ="%H:%M:%S:%OS") – Michaela Alksne Dec 06 '19 at 19:21

1 Answers1

0

Assuming you have a factor that looks like:

start.time <- c("0:13:45.9", "3:09:44.9")

Then what you wrote should work if you change the last colon to a period

as.POSIXct(start.time, format ="%H:%M:%S.%OS")