How to combine two vectors in R
· 1 min read · Updated March 15, 2026 · beginner
r vectors combining base-r
Combine vectors using base R functions.
With c()
Use c() to concatenate vectors:
x <- c(1, 2, 3)
y <- c(4, 5, 6)
combined <- c(x, y)
# [1] 1 2 3 4 5 6
This works for any atomic vector type:
letters1 <- c("a", "b")
letters2 <- c("c", "d")
c(letters1, letters2)
# [1] "a" "b" "c" "d"
With append()
Insert elements at a specific position:
result <- append(x, y, after = 2)
# [1] 1 2 4 5 6 3
Use after = 0 to prepend.