Suppose we have two vectors, x and y, defined as follows. The cbind() function is used to combine the variables such that its output contains the original variables in columns while rbind() combines the variables such that its output contains the original variables in row.įor example, the following commands will create the same matrix as x. Other commonly used approaches to create matrix are cbind() and rbind(), which are counterparts of the c() function. If we don't specify any element in the index, R will return all the elements. These commands can be used to call the element of 3 rd row and 2 nd column in matrix x. We can use the commands below to extract portions of the matrix: Where the parameter ncol is the number of columns in this matrix, and the numbers are entered by default column-wise. A two-dimensional matrix might be envisioned as a table with columns and rows, and a three-dimensional matrix might be envisioned as a series of tables stacked on top of one another.Ī matrix can be created in a number of ways. Matrices are a multi-dimensional vectors. The vectors that have been discussed previously in this module were one-dimensional, i.e., they consisted of a simple series of elements that you could imagine being organized in a single row or in a single column.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |