compmeans | R Documentation |
Calculates the means of a numerical vector according to a factor.
compmeans(x, f, w, sort = FALSE, maxlevels = 60,
user.missing, missing.include = FALSE,
plot = getOption("descr.plot"),
relative.widths = TRUE, col = "lightgray",
warn = getOption("descr.warn"), ...)
x |
A numeric vector. |
f |
A factor. |
w |
Optional vector with weights. |
sort |
If |
maxlevels |
Maximum number of levels that |
user.missing |
Character vector, indicating what levels of |
missing.include |
If |
plot |
Logical: if
in your ‘.Rprofile’ to change the default function behavior. |
relative.widths |
If |
col |
Vector with the boxes colors. |
warn |
Warn if conversion from factor into numeric or from numeric into
factor was performed and if missing values were dropped (default: |
... |
Further arguments to be passed to either
|
A matrix with class c("matrix", "meanscomp")
with labels attributes
for x
and f
. The returned object can be plotted, generating
a boxplot
of x
grouped by f
.
Jakson A. Aquino jalvesaq@gmail.com, with code for weighted boxplots written by Stefan Kraft for simPopulation package.
boxplot
.
sex <- factor(c(rep("F", 900), rep("M", 900)))
income <- 100 * (rnorm(1800) + 5)
weight <- rep(1, 1800)
weight[sex == "F" & income > 500] <- 3
attr(income, "label") <- "Income"
attr(sex, "label") <- "Sex"
compmeans(income, sex, col = "lightgray", ylab = "income", xlab = "sex")
comp <- compmeans(income, sex, weight, plot = FALSE)
plot(comp, col = c("pink", "lightblue"), ylab = "income", xlab = "sex")
library(xtable)
# If the decimal separator in your country is a comma:
# options(OutDec = ",")
print(xtable(comp, caption = "Income according to sex", label = "tab:incsx"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.