Home page for accesible maths LAB100

Style control - access keys in brackets

Font (2 3) - + Letter spacing (4 5) - + Word spacing (6 7) - + Line spacing (8 9) - +

2 Combining Vectors

Another method for creating matrices is to combine a number of vectors, either by row or by column. Consider the following matrix that has been divided according to its columns:

D = [73256890].

We can easily construct two vectors using the c command that contains the values in each of the matrix’s columns.

col1 <- c(7, 2, 6, 9)

col2 <- c(3, 5, 8, 0)

To form matrix D, the cbind command combines vectors of equal length such that each makes one of the matrix’s columns.

D <- cbind(col1, col2)

D

Alternatively, consider matrix E that has been divided according to its rows:

E = [3543\hdashline1321\hdashline2432].

Once again it is simple to construct three vectors containing the values within each row.

row1 <- c(3, 5, 4, 3)

row2 <- c(1, 3, 2, 1)

row3 <- c(2, 4, 3, 2)

row4 <- c(0, 2, 1, 3)

To form matrix E, the rbind command combines vectors of equal length such that each makes one of the matrix’s rows.

E <- rbind(row1, row2, row3, row4)

E