data_summary | R Documentation |
This function can be used to compute summary statistics for a data frame or a matrix.
data_summary(x, ...)
## S3 method for class 'data.frame'
data_summary(x, ..., by = NULL, remove_na = FALSE)
x |
A (grouped) data frame. |
... |
One or more named expressions that define the new variable name
and the function to compute the summary statistic. Example:
|
by |
Optional character string, indicating the name of a variable in |
remove_na |
Logical. If |
A data frame with the requested summary statistics.
data(iris)
data_summary(iris, MW = mean(Sepal.Width), SD = sd(Sepal.Width))
data_summary(
iris,
MW = mean(Sepal.Width),
SD = sd(Sepal.Width),
by = "Species"
)
# same as
d <- data_group(iris, "Species")
data_summary(d, MW = mean(Sepal.Width), SD = sd(Sepal.Width))
# multiple groups
data(mtcars)
data_summary(mtcars, MW = mean(mpg), SD = sd(mpg), by = c("am", "gear"))
# expressions can also be supplied as character strings
data_summary(mtcars, "MW = mean(mpg)", "SD = sd(mpg)", by = c("am", "gear"))
# count observations within groups
data_summary(mtcars, observations = n(), by = c("am", "gear"))
# first and last observations of "mpg" within groups
data_summary(
mtcars,
first = mpg[1],
last = mpg[length(mpg)],
by = c("am", "gear")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.