View source: R/groupwiseFiveNumber.r
| groupwiseFiveNumber | R Documentation |
Calculates quantiles of an ordered factor or numeric variable by one or more grouping variables
groupwiseFiveNumber(
formula = NULL,
data = NULL,
var = NULL,
group = NULL,
type = 7,
quantiles = c(0, 0.25, 0.5, 0.75, 1),
digits = 3,
...
)
formula |
A formula indicating the measurement variable and the grouping variables. e.g. y ~ x1 + x2. |
data |
The data frame to use. |
var |
The measurement variable to use. The name is in double quotes. |
group |
The grouping variable to use. The name is in double quotes. Multiple names are listed as a vector. (See example.) |
type |
The type of quantiles, as in the |
quantiles |
A vector of quantiles to determine. |
digits |
For numeric variables, the number of significant figures to use in output. |
... |
Other arguments passed to the |
The input should include either formula and data;
or data, var, and group. (See examples).
Results for ungrouped (one-sample) data can be obtained by either
setting the right side of the formula to 1, e.g. y ~ 1, or by
setting group=NULL when using var.
A data frame of requested statistics by group.
The parsing of the formula is simplistic. The first variable on the left side is used as the measurement variable. The variables on the right side are used for the grouping variables.
Salvatore Mangiafico, mangiafico@njaes.rutgers.edu
https://rcompanion.org/handbook/C_02.html
groupwiseMedian,
groupwisePercentile
Education = c("BA","PHD","BA","MA","HS","MA","HS","BA","BA","BA","MA","MA",
"AA","AA","BA","BA","PHD")
Education = factor(Education, ordered=TRUE, levels=c("HS","AA","BA","MA","PHD"))
Gender = c("female","female","male","female","male","female","male","female",
"female","female","male","male","female","male","other","female",
"female")
County = c("Elwood","Bear Lake","Elwood","Elwood","Elwood","Bear Lake","Elwood",
"Elwood","Elwood","Elwood","Elwood","Bear Lake","Elwood","Elwood",
"Elwood","Elwood","Bear Lake")
Arthur = data.frame(Gender, County, Education)
Arthur$Ed.code = as.numeric(Arthur$Education)
### One-way, two-way, and one-sample for ordered factor data
groupwiseFiveNumber(Education ~ Gender, data=Arthur, type=3)
groupwiseFiveNumber(Education ~ Gender + County, data=Arthur, type=3)
groupwiseFiveNumber(Education ~ 1, data=Arthur, type=3)
### For numeric data
groupwiseFiveNumber(Ed.code ~ Gender, data=Arthur)
### Variable notation
groupwiseFiveNumber(data=Arthur, var="Education", group="Gender", type=3)
### Asking for different quantiles
groupwiseFiveNumber(Education ~ Gender, data=Arthur, type=3,
quantiles=c(0.00, 0.05, 0.10, 0.15, 0.20, 0.25))
### Handling missing data
Arthur2 = Arthur
Arthur2$Education[1] = NA
Arthur2$Education[2] = NA
groupwiseFiveNumber(Education ~ Gender, data=Arthur2, type=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.