Home > front end >  Convering a Character to HMS in R
Convering a Character to HMS in R

Time:10-07

I am inquiring to learn how I can convert a character to hms so that I can accurately plot the mean of a series of album lengths that are in hh:mm:ss format. Here's my code. It doesn't work.

#Create labels for the mean
meanHours <- music %>%
  select(AlbumHours) %>%
summarise(hrsMean = albumHRSmean, na.rm=TRUE)  %>%
  strptime(hrsMean, "%H:%M:%S") %>%
  mutate(label_hrsMean = paste0("Mean of Hours: ",(hrsMean)))

CodePudding user response:

We could use hms() function from lubridate package:

library(lubridate)
library(dplyr)

meanHours <- music %>%
  select(AlbumHours) %>%
  summarise(hrsMean = albumHRSmean, na.rm=TRUE)  %>%
  mutate(hrsMean = hms(hrsMean),
         label_hrsMean = paste0("Mean of Hours: ",(hrsMean)))
  • Related