- Machine Learning with R Quick Start Guide
- Iván Pastor Sanz
- 80字
- 2021-06-24 16:01:29
Functions on vectors
In addition to the functions and operators that we've seen for numerical values, there are some specific functions for vectors, such as the following:
- Sum of the elements present in a vector:
sum(x)
## [1] 23
- Product of elements in a vector:
prod(x)
## [1] 360
- Length of a vector:
length(x)
## [1] 4
- Modifying a vector using the <- operator:
x
## [1] 9 8 1 5
x[1]<-22
x
## [1] 22 8 1 5