In this example I’ll show you how to find the average value of a vector using R language. First we declare a vector with the numbers we want to find the average of and write in the variable a. The declaration of the vector is obtained by the command “c” (derived from “combine”). The assignment to the variable is performed with the ” <- “operator. The command to find the average value in R language is “mean”.

> a<-c(1:10)
> mean(a)
[1] 5.5

In the example above, we initialize the vector with the numbers 1 to 10. Then we find their average value, which is 5.5.

Was this article helpful?