R/posixchange.R

Defines functions posixchange

Documented in posixchange

#' posixchange
#'
#' An easy function for calculating the total seconds of a time frame in dd:hh:mm:ss format
#' @param time_frame Your time object - could be a vector or a column (or columns) from a data frame
#' @export

posixchange <- 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
  days <- as.numeric(time_frame[[1]])
  hours <- as.numeric(time_frame[[2]])
  minutes <- as.numeric(time_frame[[3]])
  seconds <- as.numeric(time_frame[[4]])

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

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