R/timeSeries.R

timeSeries<-function
(dates, dateformat, data = NULL, tz = "GMT") 
{
  dimensions<-dim(data)
  clss<-lapply(data,class)
  if (!is.null(data)){
    if (!is.null(dimensions[1])){
      if (length(dates)!=length(data[,1]))
        stop("Data and Date lengths differ")
    }else{
      if (length(dates)!=length(data))
        stop("Data and Date lengths differ")
    }
  }	
  dates <- (strptime(paste(dates), dateformat, tz = tz))
  minute <- minute(dates)
  hour <- hour(dates)
  day <- day(dates)
  week <- week(dates)
  month <- month(dates)
  year <- year(dates)
  if (is.null(data)) {
    results <- data.frame(dates, minute, hour, day, week, 
                          month, year)
  }
  else {
    results <- data.frame(dates, minute, hour, day, week, 
                          month, year, data)
  }
  return(results)
}

Try the TSAgg package in your browser

Any scripts or data that you put into this service are public.

TSAgg documentation built on May 2, 2019, 6:09 p.m.