To concatenate two vectors in R, you can use the `c()` function.
In this example,
vector1
and vector2
.vector2
to vector1
.vector1
followed by all elements from vector2
.vector1 <- c(1, 2, 3)
vector2 <- c(4, 5, 6)
concatenated_vector <- c(vector1, vector2)
print(concatenated_vector)
[1] 1 2 3 4 5 6
In this example,
vector1
and vector2
.vector2
to vector1
.vector1
followed by all elements from vector2
.vector1 <- c('a', 'b', 'c')
vector2 <- c('d', 'e', 'f')
concatenated_vector <- c(vector1, vector2)
print(concatenated_vector)
[1] "a" "b" "c" "d" "e" "f"
In this tutorial, we learned How to Concatenate Two Vectors in R language with well detailed examples.