10) Combine Vectors to make a Matrix with rbind.

This Blog entry is from the Data Structures section in Learn R.

Whereas cbind() brought vectors together as columns,   rbind() can bring vectors together as rows.  Start by creating two vectors in a script block:

Row1 <- c(1,2,3,4,5,6,7,8,9,10)
Row2 <- c(10,20,30,40,50,60,70,80,90,100)
Row3 <- c(100,200,300,400,500,600,700,800,900,1000)
creating-vectors-of-the-same-size-in-r-script.png

Run the script block to console:

creating-vectors-of-same-size-writen-to-r-console.png

To bind the vectors as rows use the rbind() function:

Matrix3Row <- rbind(Row1,Row2,Row3)
script-to-use-rbind-function-to-create-matrix-as-rows-in-r.png

Run the line of script to console:

matrix-created-from-rbind-written-to-r-console.png

The matrix can be viewed by typing:

Matrix3Row
script-to-write-out-matrix-created-by-rbind-in-r.png

Run the line of script to console:

matrix-created-by-r-bind-written-out-to-r-console.png