R/hms_fix.R

Defines functions hms_fix

Documented in hms_fix

#' hms_fix
#'
#' An easy function for calculating the total seconds of a time object
#' @param time_frame Your time object - could be a vector or a column (or columns) from a data frame
#' @export

hms_fix <- function(time_frame) {

  time_frame <- as.character(time_frame)
  time_frame <- str_split(time_frame,fixed(":")) #split the time into elements
  time_frame <- time_frame[[1]] #convert from list to vector
  hours <- as.numeric(time_frame[[1]])
  minutes <- as.numeric(time_frame[[2]])
  seconds <- as.numeric(time_frame[[3]])

  z <- (hours * 3600) + (minutes * 60) + seconds

  return(z)
}
neugelb/neugelbtools documentation built on July 7, 2020, 1:17 a.m.