Section 15 Vector Operation: Statistical Function

15.1 Descriptive statistics

Function Explanation
length Number of elements in a vector
sum Sum of the values in a vector
min Minimum of a vector
max Maximum of a vector
range Range (min, max) of a vector
mean Mean of the values in a vector
median Median of the values in a vector
var Variance
sd Standard deviation

15.2 Example 1

15.2.1 Apply function on a vector

x <- c(0, 2, 4, 6)
mean(x)
sd(x)

15.3 Example 2

15.3.1 Both vectors are of the same length

x <- c(0, 2, 4, 6)
y <- c(4, -2, 7, 9)
cov(x,y)
cor(x,y)

15.4 Example 3

15.4.1 The longer vector is a multiple of the shorter vector

x <- c(0, 2, 4, 6)
y <- c(4, -2)
mean(x) + mean(y)
cov(x,y)
cor(x,y)

15.5 Example 4

15.5.1 The longer vector is NOT a multiple of the shorter vector

x <- c(0, 2, 4, 6)
y <- c(4, -2, 7)
mean(x) + mean(y)
cov(x,y)
cor(x,y)