Learn R Programming

IDPmisc (version 0.9.3)

rose: Creates a rose object out of circular data

Description

rose splits data into subsets according to one or two grouping elements, computes summary statistics for each, and returns the result in a rose object.

Usage

rose(x, subset = NULL,
     cyclVar = NULL, circle = NULL, n.cyclVar = 8,
     cut = NULL, labels = NULL,
     breaks = NULL, include.lowest = FALSE, right = TRUE, dig.lab = 2, 
     warn = TRUE, FUN = mean, ...)

Arguments

x
Vector, data frame or matrix containing the response.
subset
An optional vector specifying a subset of observations to be used in the aggregating process.
cyclVar
Cyclic variable as first grouping element. cyclVar must be a numeric vector whose length is equal to the number of rows in x with 0 <= cyclVar < circle. Observations where cyclic variab
circle
Defines the value of a full circle with no default.
n.cyclVar
Defines the number of equally spaced intervals of the cyclic variable, into which the data are split. The first interval is labeled with 0 and is always centered around 0.
cut
Vector of numerics, logicals or factors as second grouping elements. Its length is equal to the number of rows in x. cut is used to group the observations similar to function
labels
Labels for the corresponding intervals. When cut is a logical, labels has to be named in the order: FALSE, TRUE.
breaks, include.lowest, right, dig.lab
These arguments are only active when cut is numeric and are used in exactly the same way as in cut. breaks defines the break points. include.lowest = TRUE in
warn
Logical, indicating if warnings should be issued for NAs in cyclVar and / or x-values outside of breaks range.
FUN
Summary function, returning a scalar or vector.
...
Additional arguments for summary function.

Value

  • Object of class rose

Details

The first grouping element, cyclVar, for the summary statistics must be circular and numeric. The second grouping element, cut, can be numeric, logical or a factor. \crNotall combinations of arguments are allowed: \crArgumentcut can only be defined when summary consists of a scalar and x consists of 1 column. \crWhenx contains only one column and cut is not defined, the summary function may also be a vector with the restriction, that the summary of each subset, defined by the cyclic variable, must have the same number of elements. \crWhenx is a data frame or matrix with more than 1 column, the summary function must be scalar.

See Also

rose-class, plot.rose, cart2clock, clock2cart

Examples

Run this code
## artificial example:
## concentration of A and B as function of
## hour of day (hour) and wind direction (WD)
hour <- rep(0:23,100)
dat <- data.frame(hour = hour,
                  A =    (2*cos((hour+6)/6*pi)+rnorm(24*100,1))^2,
                  B =    (2*cos((hour+4)/6*pi)+rnorm(24*100,1,2))^2,
                  WD =   rnorm(24*100,
                           mean=sample(c(190,220,50),24*100, replace = TRUE),
                           sd=30)%%360)

## two different responses, scalar summary function
mean.windrose <- rose(dat[,c("A","B")],
                      cyclVar=dat$WD,
                      circle=360,
                      FUN=mean, na.rm=TRUE)
mean.windrose

## one response, vectorial summary function
quant.dayrose <- rose(dat$A,
                      cyclVar=dat$hour,
                      n.cyclVar=24, circle=24,
                      FUN=quantile, na.rm=TRUE)
quant.dayrose


mean.windroseB <- rose(dat[,c("A")],
                       cyclVar=dat$WD,
                       circle=360,
                       cut=dat$B,
                       breaks=c(0,30,100),
                       dig.lab=3,
                       FUN=mean, na.rm=TRUE)
mean.windroseB

Run the code above in your browser using DataLab