Calculates multiple percentile values from a time series, with flexible time aggregation.

calcPercentile(mydata, pollutant = "o3", avg.time = "month",
  percentile = 50, data.thresh = 0, start = NA)

Arguments

mydata

A data frame of data with a date field in the format Date or POSIXct. Must have one variable to apply calculations to.

pollutant

Name of variable to process. Mandatory.

avg.time

Averaging period to use. See timeAverage for details.

percentile

A vector of percentile values. For example percentile = 50 for median values, percentile = c(5, 50, 95 for multiple percentile values.

data.thresh

Data threshold to apply when aggregating data. See timeAverage for details.

start

Start date to use - see timeAverage for details.

Value

Returns a data frame with new columns for each percentile level. New columns are given names like percentile.95 e.g. when percentile = 95 is chosen. See examples below.

Details

This is a utility function to calculate percentiles and is used in, for example, timePlot. Given a data frame with a date field and one other numeric variable, percentiles are calculated.

See also

Examples

# 95th percentile monthly o3 concentrations percentiles <- calcPercentile(mydata, pollutant ="o3", avg.time = "month", percentile = 95) head(percentiles)
#> date percentile.95 #> 1 1998-01-01 14 #> 2 1998-02-01 7 #> 3 1998-03-01 15 #> 4 1998-04-01 20 #> 5 1998-05-01 25 #> 6 1998-06-01 15
# 5, 50, 95th percentile monthly o3 concentrations
# NOT RUN { percentiles <- calcPercentile(mydata, pollutant ="o3", avg.time = "month", percentile = c(5, 50, 95)) head(percentiles) # }