# How to create a matrix from two given vectors in R in RStudio?

Suppose, $$c(1, 2, 3, 4)$$ and $$c(2, 4, 5, 6)$$ are two vectors. Then in R or RStudio,

How to create a $$4\times 2$$ matrix from these two vectors?

Also,

how to add another vector $$c(8, 9, 10, 11)$$ as a column to the previous matrix?

x <- c(1, 2, 3, 4)

y <- c(2, 4, 5, 6)

z <- matrix(c(x, y), nrow = length(x))

zz <- cbind(z, c(8, 9, 10, 11))


• The first solution works but is not as instructive as a simple cbind(x, y). May 2 '20 at 19:46
• @Nick F, it says that "function lenght is not found". How to fix this issue?
– gete
May 2 '20 at 19:54
• @MichaelM It says that "function lenght is not found". How to fix this issue?
– gete
May 2 '20 at 20:00
• By switching the t and the h ;-) May 2 '20 at 20:56
• @MichaelM fair point on cbind for all parts being cleaner. May 2 '20 at 22:00