basic_stats | R Documentation |
Calculate basic statistics (e.g. mean
, min
, max
, sd
, IQR
) from a numeric vector.
basic_stats(
x,
f = list(min = min, mean = mean, median = stats::median, max = max, sd = stats::sd, IQR
= stats::IQR, MAD = stats::mad),
p = function(x) round(x, digits = 2),
output = "wdf",
...
)
x |
A numeric vector for which to calculate statistics. |
f |
A named list of functions which are used to calculate statistics. |
p |
A function for processing summary statistics. The default is a function which rounds each output to the nearest two decimal places. |
output |
A character specifying the format in which summary statistics should be returned. The currently implemented options are: (1) |
... |
Other arguments that apply to all functions in |
Basic statistics for a vector of numbers, either in the format of a numeric vector, a long-format dataframe or a wide-format dataframe depending on the input to output
(see above).
Edward Lavender
#### Define a vector:
x <- runif(10, 0, 10)
#### Example (1): Numeric vector output
basic_stats(x, output = "vec")
#### Example (2): Long-format dataframe output
basic_stats(x, output = "ldf")
#### Example (3): Wide-format dataframe output
basic_stats(x, output = "wdf")
#### Example (4): Functions can be adjusted in f argument by supplying a named list:
basic_stats(x,
f = list(median = median,
quantile25 = function(x) { quantile(x, prob = 0.25) }),
output = "ldf"
)
#### Example (5) Save typing by passing any arguments that apply to all functions via ...
basic_stats(c(x, NA), f = list(mean = mean, min = min), na.rm = TRUE)
#### Example (6) Unsupported outputs return a warning and the function defaults to 'ldf'
## Not run:
basic_stats(1:10, output = "df")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.