Following is a preview of the matrix x:
Code:
[,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6
Write the code that return the output:
[,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [3,] 7 8 9
Adding row to the matrix in R:
# adding row to matrix
# taking given matrix
mat1=matrix(c(1:6),nrow=2,ncol=3,byrow=FALSE)
print(mat1)
# here rbind() will combine vectors.Here we are combining vector [7
8 9] to the original matrix
mat2=rbind(mat1,c(7:9))
print(mat2)
output:
Get Answers For Free
Most questions answered within 1 hours.