Description Usage Arguments Value Examples
Subtract mean values by grouping factor. Accepts either two vectors (data and groups) or
a data.frame
and a formula of the form data ~ groups
.
1 2 3 4 5 6 7 8 9 | group_demean(...)
## S3 method for class 'numeric'
group_demean(x, groups, digits = getOption("digits"),
named = FALSE, ...)
## S3 method for class 'formula'
group_demean(f, data, digits = getOption("digits"),
named = FALSE, ...)
|
... |
arguments passed to specific methods. |
x |
a numeric vector. |
groups |
a vector of the same length as |
digits |
an integer passed directly to |
named |
If |
f |
a formula. For use with the |
data |
a |
A vector of the same length as the input data (either x
or the input
column from the data.frame
data
) where group means have been subtracted
from each element in the input data. Specifically, residuals are reported the ordinary
least squares regression lm(x ~ factor(groups))
.
1 2 3 4 5 6 | # using a numeric vector and corresponding grouping vector
x <- runif(50)
g <- rep(letters[1:5], 10)
group_demean(x, g)
# using a formula and data.frame
group_demean(mpg ~ cyl, mtcars)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.