| rose {IDPmisc} | R Documentation |
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.
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, ...)
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 variables are NA are
automatically excluded from the rose object. |
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 cut. |
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 indicates that the lowest (or
highest, for right = FALSE) breaks value should be also included.
right = TRUE indicates that the intervals should be closed
on the right (and open on the left) or vice versa for right =
FALSE.
dig.lab number of digits for breaks labeling when labels
are not given explicitely. |
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. |
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.
Not all combinations of arguments are allowed:
Argument cut can only be defined when summary consists of a
scalar and x consists of 1 column.
When x 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.
When x is a data frame or matrix with more than 1 column,
the summary function must be scalar.
Object of class rose
Rene Locher
rose-class, plot.rose, cart2clock,
clock2cart
## 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