How to get Vector Length in R?
We use syntax length() function to get length of a vector in R programming by passing the vector to it. The length() function will then returns an integer, representing the length of vector.
Example:
m1 <- c(1,2,3,4,5)
vector_length1 = length(m1)
cat("Vector m1 has length :", vector_length1)
m2 <- c("hello", "welcome", "home")
vector_length2 = length(m2)
cat("Vector m2 has length :", vector_length2)
#output:
Vector m1 has length : 5
Vector m2 has length : 3
