R – Append Vector to Another Vector
In this tutorial, we will learn how to append a vector to another vector in R programming Language.
To append one vector to another in R, call append()
function and pass the two vectors as arguments. append()
returns a new vector with the elements of first vector appended with that of second vector.
Syntax
The syntax to append vector y
to vector x
is
</>
Copy
append(x, y)
append()
does not modify the original vector, but creates and returns a new vector.
Examples
In this example, we take two vectors x
and y
, append elements of vector y
to the elements of vector x
.
Example.R
</>
Copy
x <- c(2, 4, 6)
y <- c(8, 10, 12)
result <- append(x, y)
print(result)
Output
[1] 2 4 6 8 10 12
Conclusion
In this R Tutorial, we learned how to append a vector to another vector in R, with the help of example programs.