dataframe2zoo: Extract ZOO Time Series of Cases from a Tycho 2.0 dataframe

Description Usage Arguments Details Value Examples

View source: R/dataframe2zoo.R

Description

extractzoo and tycho2zoo extracts regular time series of class zooreg from a dataframe or tibble.

Usage

1
2
3
4
dataframe2zoo(dataset, index, data, FUN = "sum")

tycho2zoo(dataset, index = "PeriodEndDate", data = "CountValue",
  FUN = "sum")

Arguments

dataset

Data Frame or Tibble with at least one variabel of class Date, POSIXct or POSIXlt.

index

Character. Name of variable to use as index. Variable must be of class Date, POSIXct or POSIXlt

data

Character. Name of variable to use as data.

FUN

Name of function to use for aggregation. May be quoted or not. Default = sum

Details

extractzoo aggregates the data by summing for each unique value of index, calculates the underlying time interval of the data, pads missing data with NA's, and returns a regular time series (numeric vector) of class zooreg. See zooreg for details.

tycho2zoo is a convenience wrapper for extractzoo with default values index = "PeriodEndDate" and data = "CountValue".

Value

A regular time series of class zooreg.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mydata <- data.frame(date = as.Date(c("2000/1/1",
                                          "2000/1/1",
                                          "2000/1/8",
                                          "2000/1/22",
                                          "2000/1/29",
                                          "2000/1/29")),
                         city = c("NY","BOS","NY","NY","BOS","NY"),
                         temp = c(2.0, 0.5, 5.5, 3.8, 7.1, 9.0))
mydata
meantemp <- dataframe2zoo(mydata, index="date", data="temp", FUN=mean)
meantemp

allopole/tycho2 documentation built on Dec. 26, 2019, 2:48 a.m.