Descriptive Statistics in R-Studio
By crackeconomicsandstatistics on 1 Jan 2021 • ( Leave a comment )
Introduction
Descriptive statistics are used to describe and represent the data we have. There are two types of
descriptive statistics: Measures of Central Tendency and Measures of Dispersion.
Let’s take the following example to calculate the descriptive statistics in R-Studio.
Define a variable, “X1” in R-Studio as follows:
X1 <- c(2,5,10,23,12,15,1,16,31)
X1
Press Run button or Ctrl+Enter to execute the command.
Watch YouTube Video here:
Measures of Central Tendency
This measure identifies the central position of the data to describe it. For example mean, median
and mode.
Mean
Write this command in R Script: mean (X1) → Press Run to execute the command.
Ans:
mean (X1)
[1] 12.77778
Median
Write this command in R Script: median (X1) → Press Run to execute the command.
Ans:
median (X1)
[1] 12
Measures of Dispersion
This measures the dispersion in the data. In other words, it shows the scattering of the data. For
example, range, standard deviation, variance, etc.
Maximum and Minimum Value:
Write this command in R Script: max (X1) and min (X1) → Press Run to execute the command.
Ans:
max (X1)
[1] 31
min (X1)
[1] 1
Range:
Write this command in R Script: range (X1) → Press Run to execute the command.
Ans:
range (X1)
[1] 1 31
Standard Deviation
Write this command in R Script: sd (X1) → Press Run to execute the command.
Ans:
sd (X1)
[1] 9.846037
Variance
Write this command in R Script: sd (X1) → Press Run to execute the command.
Ans:
var (X1)
[1] 96.94444
The following two commands are useful to find all the descriptive statistics together:
1. Summary command: Write this command in R Script: summary (X1) → Press Run to
execute the command.
Ans:
summary (X1)
Min. 1stQu. Median Mean 3rd Qu. Max.
1.00 5.00 12.00 12.78 16.00 31.00
2. Describe command: Write this command in R Script: describe (X1) → Press Run to execute
the command.
Ans:
describe (X1)
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 9 12.78 9.85 12 12.78 10.38 1 31 30 0.44 -1.13 3.28
We need to download the “psych” package to use the describe command. Kindly follow the
procedure mentioned below:
[Link] (“psych”)
library (psych)
[Link]