Hiding Hours in dataframe with hms format

Hello,

I have a dataframe where I was able to convert all the values into the hms format, but none of my times have anything in the hours place because they are swimming times. Is there a way to remove it so it only shows minutes and seconds. It is only for the purpose of cleaning up my table so it does not need to remain in the same format.

Here's a simpler version of my data:

library(hms)

df <- data.frame(Name = c("Swimmer 1","Swimmer 2", "Swimmer 3"),
                 Event.1 = c(22.50,25.90,27.56),
                 Event.2 = c(54.23,"1:01.13",59.54),
                 Event.3 = c("1:41.12","1:58.13","2:03.15")
)

data.2 <- df %>%
  mutate(across(.cols = -Name, 
                .fns = ~ if_else(!str_detect(., ":"), paste0("00:00:", .), paste0("00:", .))),
         across(.cols = -Name,
                .fns = parse_hms))
suppressPackageStartupMessages({
  library(dplyr)
  library(stringr)
})


DF <- data.frame(Name = c("Swimmer 1","Swimmer 2", "Swimmer 3"),
                 Event.1 = c(22.50,25.90,27.56),
                 Event.2 = c(54.23,"1:01.13",59.54),
                 Event.3 = c("1:41.12","1:58.13","2:03.15"))

pattern <- "\\.\\d+$"

DF <- DF %>% mutate(across(.cols = -Name, .fns = as.character)) 

DF %>% mutate(Event.1 = str_remove_all(Event.1,pattern),
              Event.2 = str_remove_all(Event.2,pattern),
              Event.3 = str_remove_all(Event.3,pattern))
#>        Name Event.1 Event.2 Event.3
#> 1 Swimmer 1      22      54    1:41
#> 2 Swimmer 2      25    1:01    1:58
#> 3 Swimmer 3      27      59    2:03

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.