Section 27 Vector Operation: Statistical Function
27.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 |
27.2 Example 1
27.2.1 Apply function on a vector
<- c(0, 2, 4, 6)
x mean(x)
sd(x)
27.3 Example 2
27.3.1 Both vectors are of the same length
<- c(0, 2, 4, 6)
x <- c(4, -2, 7, 9)
y cov(x,y)
cor(x,y)
27.4 Example 3
27.4.1 The longer vector is a multiple of the shorter vector
<- c(0, 2, 4, 6)
x <- c(4, -2)
y mean(x) + mean(y)
cov(x,y)
cor(x,y)
27.5 Example 4
27.5.1 The longer vector is NOT a multiple of the shorter vector
<- c(0, 2, 4, 6)
x <- c(4, -2, 7)
y mean(x) + mean(y)
cov(x,y)
cor(x,y)