R provides a wide range of functions for obtaining summary statistics. One method of obtaining descriptive statistics is to use the sapply( ) function with a specified summary statistic.
# get means for variables in data frame mydata# excluding missing values
sapply(mydata, mean, na.rm=TRUE)Obsługiwane przez
Possible functions used in sapply include mean, sd, var, min, max, median, range, and quantile.
There are also numerous R functions designed to provide a range of descriptive statistics at once. For example
# mean,median,25th and 75th quartiles,min,max
summary(mydata)# Tukey min,lower-hinge, median,upper-hinge,max
fivenum(x)Obsługiwane przez
The doBy package provides much of the functionality of SAS PROC SUMMARY. It defines the desired table using a model formula and a function. Here is a simple example.
library(doBy)
summaryBy(mpg + wt ~ cyl + vs, data = mtcars,
FUN =function(x){
c(m = mean(x), s = sd(x))})# produces mpg.m wt.m mpg.s wt.s for each# combination of the levels of cyl and vsObsługiwane przez
R provides a wide range of functions for obtaining summary statistics. One method of obtaining descriptive statistics is to use the sapply( ) function with a specified summary statistic.
Possible functions used in sapply include mean, sd, var, min, max, median, range, and quantile.
There are also numerous R functions designed to provide a range of descriptive statistics at once. For example
Using the Hmisc package
Using the pastecs package
Using the psych package
Summary Statistics by Group
A simple way of generating summary statistics by grouping variable is available in the psych package.
The doBy package provides much of the functionality of SAS PROC SUMMARY. It defines the desired table using a model formula and a function. Here is a simple example.
See also : aggregating data.
To Practice
Want to practice interactively? Try this free course on statistics and R