-1

I have a column - avg_pace - which I want to use as a time in the format %M %S .%f (I think that's right for milliseconds, but please correct me).

garmin2 <- garmin %>%
  strptime(avg_pace, "%M:%S:.%f")

This doesn't work for me - I keep getting that strptime can't find avg_pace - but I've used it elsewhere.

ArtixModernal
  • 661
  • 2
  • 8
  • 21
  • `strptime()` is a base function that takes a character vector as it's first parameter, right now your are piping a whole data.frame (?) as a first parameter and next parameters are also shifted. you probably meant to use it in `mutate()` . Please consider editing your question to include minimal reproducible example - https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example - so others would have an idea how your `garmin` dataset( or list? or vector?) looks like. I.e. output of `dput(head(garmin))` – margusl Oct 24 '22 at 11:12

1 Answers1

1

Fractional seconds are defined in the POSIXlt format standards using %OS (see ?strptime). You need to specify this format both in parsing the time and in printing it out:

times <- c("10:56.391", "25:21.188")
times2 <- strptime(times, "%M:%OS")

# default printing: not what you want (note that it defaults to today's date)
times2
[1] "2022-10-24 00:10:56 BST" "2022-10-24 00:25:21 BST"

# specify printing format with %OS and the number of fractional second digits
format(times2, "%M:%OS3")
[1] "10:56.391" "25:21.188"
Ottie
  • 1,000
  • 3
  • 9