| summaryStats | R Documentation |
Produces a table of summary statistics for the data. If the argument
group is missing, calculates a matrix of summary statistics for the
data in x. If group is present, the elements of group
are interpreted as group labels and the summary statistics are displayed for
each group separately.
summaryStats(x, ...)
## Default S3 method:
summaryStats(
x,
group = rep("Data", length(x)),
data.order = TRUE,
digits = 2,
...
)
## S3 method for class 'formula'
summaryStats(x, data = NULL, data.order = TRUE, digits = 2, ...)
## S3 method for class 'matrix'
summaryStats(x, data.order = TRUE, digits = 2, ...)
x |
either a single vector of values, a formula of the form
|
... |
Optional arguments that are passed to the summary statistic functions.
For example |
group |
a vector of group labels. |
data.order |
if |
digits |
the number of decimal places to display. |
data |
an optional data frame containing the variables in the model. |
A teaching summary is printed as a side effect. The returned value is invisible so that classroom use can focus on the printed summary while programmatic use can still save the result.
If x is a single variable and no grouping is supplied, an invisible
list is returned with the following named items:
min |
Minimum value. |
max |
Maximum value. |
mean |
Mean value. |
var |
Variance – the average of the squares of the deviations of the data values from the sample mean. |
sd |
Standard deviation – the square root of the variance. |
n |
Number of data values – size of the dataset. |
nMissing |
If there are missing values, and |
iqr |
Midspread (IQR) – the range spanned by the central half of the data; the interquartile range. |
skewness |
Skewness statistic – indicates how skewed the data set is. Positive values indicate right-skew data. Negative values indicate left-skew data. |
lq |
Lower quartile. |
median |
Median – the middle value when the batch is ordered. |
uq |
Upper quartile. |
If grouping is provided, either by using the group argument, by using
a formula, or by passing a matrix whose columns represent groups, the
function invisibly returns a data.frame with one row for each group
and columns containing the summary statistics.
summaryStats(default): Summary Statistics
summaryStats(formula): Summary Statistics
summaryStats(matrix): Summary Statistics
## STATS20x data:
data(course.df)
## Single variable summary
with(course.df, summaryStats(Exam))
## Using a formula
summaryStats(Exam ~ Stage1, course.df)
## Using a matrix
courseMatrix = cbind(course.df$Exam, course.df$Assign, course.df$Test)
summaryStats(courseMatrix)
## Saving and extracting the information
sumStats = summaryStats(Exam ~ Degree, course.df)
sumStats
## Just the BAs
sumStats['BA', ]
## Just the means
sumStats$mean
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.