TSstats: Compute various antecedent summary statistics from time...

View source: R/TSstats.R

TSstatsR Documentation

Compute various antecedent summary statistics from time series data for specified windows of time

Description

Compute various stats for time series data over a period of time Originally scripted for NOAA Great Lakes model from GDP for given set of dates and time periods, but could be used for any time series. File format must include the POSIX formatted date (yyyy-mm-ddThh:mm:ssZ), and then columns of values with the time series data

read date with format mm/dd/yy hh:mm (use koepkeSM$date <- as.POSIXct(koepkeSM$Date,"

read date with format mm/dd/yyyy hh:mm cedardates$psdate <- as.POSIXct(cedardates$Startdate," cedardates$parfdate <- as.POSIXct(cedardates$Enddate,"

Subset the data by begin and end date (can also assign to a df if you like) then define min mean median and max for the subset. Do this for all date periods in the file.

Usage

TSstats(
  df,
  date = "date",
  varnames,
  dates,
  starttime = "psdate",
  times = c(1, 2),
  units = "hours",
  stats.return = c("mean"),
  subdfvar = "",
  subdfvalue = "",
  subdatesvar = "",
  subdatesvalue = "",
  out.varname = ""
)

Arguments

df

dataframe Unit values file

date

string Date column in POSIX format in unit values file

varnames

string Column name with unit values

dates

dataframe File with sample dates

starttime

string Column in sample dates file with dates in POSIX format, defaults to "psdate"

times

vector to define desired processing times. Zero indicates then nearest or nearest previous value. Default is hours, but can be specified using "units" variable

units

string Units of times vector. Can be any of the following: "minutes","min","mins","hours","hr","hrs","day","days","week","weeks"

stats.return

string Options include "mean","max","min","median","sum","sd","maxdiff","difference",nearest","nearprev" maxdiff is the maximum value minus the minimum value for the time period, difference is the latest minus the first value, nearest is the closest value in time, nearprev is the closest value previous to the specified time, nearest and nearprev require a 0 in the times vector,

subdfvar

string column name in UVdf with names of parameters, default is ""

subdfvalue

string Optional: value of varname to use in subsetting df, default is ""

subdatesvar

string Optional: subset dates data frame by a value in this column, default is ""

subdatesvalue

string Optional: value to use in subsetting

out.varname

string

Value

dates dataframe

Examples

flowData <- flowData
sampleData <- sampleData
TSstats(df=flowData,date="pdate",varnames="Q",
        dates=sampleData,starttime="Hbpdate",times=c(1,3,6,12,24),
        units="hrs",stats.return=c("mean","max","sd"),out.varname="Q")

USGS-R/USGSHydroTools documentation built on April 17, 2023, 8:09 p.m.