To append a vector to another vector in R, you can use the `c()` function to concatenate the vectors.
In this example,
vector1
and vector2
with different values.vector2
to vector1
.vector1
followed by all elements from vector2
.vector1 <- c(1, 2, 3, 4)
vector2 <- c(5, 6, 7)
combined_vector <- c(vector1, vector2)
print(combined_vector)
[1] 1 2 3 4 5 6 7
In this example,
numeric_vector
and char_vector
with different values.char_vector
to numeric_vector
.char_vector
are converted to character representations and appended to numeric_vector
.numeric_vector <- c(1, 2, 3)
char_vector <- c('a', 'b', 'c')
combined_vector <- c(numeric_vector, char_vector)
print(combined_vector)
[1] "1" "2" "3" "a" "b" "c"
In this tutorial, we learned How to Append a Vector to another Vector in R language with well detailed examples.