In R, you can join vectors using the `c()` function or the `append()` function.
In this example,
vector1
and vector2
, with different elements.c()
function to concatenate the two vectors into a single vector.# Define two vectors
vector1 <- c(1, 2, 3)
vector2 <- c(4, 5, 6)
# Join vectors using c() function
combined_vector <- c(vector1, vector2)
# Print the combined vector
print(combined_vector)
[1] 1 2 3 4 5 6
In this example,
vector1
and vector2
, with different elements.append()
function to append elements of vector2
to vector1
.# Define two vectors
vector1 <- c(1, 2, 3)
vector2 <- c(4, 5, 6)
# Join vectors using append() function
for (element in vector2) {
vector1 <- append(vector1, element)
}
# Print the combined vector
print(vector1)
[1] 1 2 3 4 5 6
In this tutorial, we learned How to Join Vectors in R language with well detailed examples.