I have a vector v, and I would like to create the following matrix. How can I do this in R?
v
v = c(1, 2, 3, 4) > m = matrix(c(1, 1, 1
See ?matrix and the nrow, ncol, byrow arguments:
?matrix
nrow
ncol
byrow
matrix(v, nrow=4, ncol=4, byrow=TRUE) # [,1] [,2] [,3] [,4] #[1,] 1 2 3 4 #[2,] 1 2 3 4 #[3,] 1 2 3 4 #[4,] 1 2 3 4