Learn R Programming

pcts (version 0.15.8)

pcApply-methods: Apply a function to each season

Description

Apply a function to each season.

Usage

pcApply(object, ...)

# S4 method for numeric pcApply(object, nseasons, FUN, ...)

# S4 method for matrix pcApply(object, nseasons, FUN, ...)

# S4 method for PeriodicTS pcApply(object, FUN, ...)

# S4 method for PeriodicMTS pcApply(object, FUN, ...)

Value

numeric or matrix for the methods described here, see section Details.

Arguments

object

an object for which periodic mean makes sense.

nseasons

number of seasons.

FUN

a function, as for apply.

...

further arguments for FUN.

Author

Georgi N. Boshnakov

Methods

signature(object = "matrix")

signature(object = "numeric")

signature(object = "PeriodicMTS")

signature(object = "PeriodicTS")

Details

For univariate periodic time series, pcApply applies FUN to the data for each season. For multivariate periodic time series, this is done for each variable.

The methods for "numeric" and "matrix" are equivalent to those for "PeriodicTS" and "PeriodicMTS", respectively. The difference is that the latter two don't need argument nseasons and take the names of the seasons from object.

Argument "..." is for further arguments to FUN. In particular, with many standard R functions argument na.rm = TRUE can be used to omit NA's, see the examples.

In the univariate case, when length(object) is an integer multiple of the number of seasons the periodic mean is equivalent to apply(matrix(object, nrow = nseasons), 1, FUN, ...).

See Also

pcMean, apply

Examples

Run this code
pcApply(pcts(presidents), mean, na.rm = TRUE)
pcMean(pcts(presidents), na.rm = TRUE) # same

pcApply(pcts(presidents), median, na.rm = TRUE)
pcApply(pcts(presidents), var, na.rm = TRUE)
pcApply(pcts(presidents), sd, na.rm = TRUE)

pcfr2to4 <- pcts(dataFranses1996)[2:4]
pcApply(pcfr2to4, median, na.rm = TRUE)
pcApply(pcfr2to4, sd, na.rm = TRUE)

Run the code above in your browser using DataLab