Descriptive Statistics
How to Perform Descriptive Statistics in R
By Chi Kit Yeung in Statistics R
January 13, 2023
Applying descriptive statistics in R
Fundamentals
data("PlantGrowth")
data <- PlantGrowth
head(data)
## weight group
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.50 ctrl
## 6 4.61 ctrl
str(data)
## 'data.frame': 30 obs. of 2 variables:
## $ weight: num 4.17 5.58 5.18 6.11 4.5 4.61 5.17 4.53 5.33 5.14 ...
## $ group : Factor w/ 3 levels "ctrl","trt1",..: 1 1 1 1 1 1 1 1 1 1 ...
by(data, data$group, summary)
## data$group: ctrl
## weight group
## Min. :4.170 ctrl:10
## 1st Qu.:4.550 trt1: 0
## Median :5.155 trt2: 0
## Mean :5.032
## 3rd Qu.:5.293
## Max. :6.110
## ------------------------------------------------------------
## data$group: trt1
## weight group
## Min. :3.590 ctrl: 0
## 1st Qu.:4.207 trt1:10
## Median :4.550 trt2: 0
## Mean :4.661
## 3rd Qu.:4.870
## Max. :6.030
## ------------------------------------------------------------
## data$group: trt2
## weight group
## Min. :4.920 ctrl: 0
## 1st Qu.:5.268 trt1: 0
## Median :5.435 trt2:10
## Mean :5.526
## 3rd Qu.:5.735
## Max. :6.310
Central Tendency
library(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
## The following object is masked from 'package:tidyr':
##
## extract
stat.desc(data)
## weight group
## nbr.val 30.0000000 NA
## nbr.null 0.0000000 NA
## nbr.na 0.0000000 NA
## min 3.5900000 NA
## max 6.3100000 NA
## range 2.7200000 NA
## sum 152.1900000 NA
## median 5.1550000 NA
## mean 5.0730000 NA
## SE.mean 0.1280195 NA
## CI.mean.0.95 0.2618293 NA
## var 0.4916700 NA
## std.dev 0.7011918 NA
## coef.var 0.1382204 NA