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
x <- c(0, 2, 4, 6)
mean(x)
sd(x)27.3 Example 2
27.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)27.4 Example 3
27.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)27.5 Example 4
27.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)