meanDeviations | R Documentation |
Tiny helper function to calculate the mean and deviations from the mean, both returned as a list. Works nicely with data.table to calculate a between and within variable.
meanDeviations(x, na.rm = TRUE)
x |
A vector, appropriate for the |
na.rm |
A logical, whether to remove missing
or not. Defaults to |
A list of the mean (first element) and deviations from the mean (second element).
## simple example showing what it does
meanDeviations(1:10)
## example use case, applied to a data.table
library(data.table)
d <- as.data.table(iris)
d[, c("BSepal.Length", "WSepal.Length") := meanDeviations(Sepal.Length),
by = Species]
str(d)
rm(d)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.