average_ts | R Documentation |
This function averages a time series (i.e., all of the values of a response variable collected through time) in each of a series of user-specified bins. The function can handle independent time series (e.g., for multiple individuals), average numeric explanatory variables alongside the response, incorporate other 'static' variables (e.g., the sex of each individual) and implement different types of averages.
average_ts( dat, split = NULL, timestamp, response, breaks, fun = mean, first = NULL, average = NULL, as_time = as.POSIXct, order = c(timestamp, response, first, average), verbose = TRUE, ... )
dat |
A dataframe which includes observations collected over time. |
split |
(optional) A character that defines the name of the column in |
timestamp |
A character that defines the name of the column in |
response |
A character that defines the name of the column in |
breaks |
A number or vector which defines the number of unique cut points or the unique cut points themselves at which each independent time series is cut into bins. This is passed to |
fun |
A function used to calculate the average response and the average value of any other other numeric variable specified in |
first |
(optional) A character vector that defines the name(s) of the column(s) in |
average |
(optional) A character vector that defines the name(s) of any other column(s) in |
as_time |
A function that converts a character vector of breaks into a vector of times. The default function is |
order |
A character vector of column names that defines the order of desired columns in the returned dataframe. |
verbose |
A logical input that defines whether or not to return messages to the console to monitor function progress. |
... |
Additional arguments passed to |
The function returns a dataframe in which time stamps have been aggregated into a sequence of bins and the value of the response and any other numeric columns requested have been averaged over all the data in each bin. For static variables (e.g., the sex of an individual), the first observation for each independent time series may also be included.
Edward Lavender
summarise_in_bins
dat_flapper_av <- average_ts(dat = dat_flapper, split = "id", timestamp = "timestamp", response = "depth", breaks = "hours", first = "id", average = "temp" ) utils::head(dat_flapper_av)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.