In R, a matrix is a collection of elements of the same data type organized into a fixed number of rows and columns. To create a matrix in R, you can use the matrix()
function.
Here's an example of creating a matrix with 3 rows and 4 columns:
main.r94 chars6 lines
main.r100 chars5 lines
You can access elements of a matrix using indexing. To access the element in the second row and third column of my_matrix
:
main.r63 chars3 lines
You can also access entire rows or columns of a matrix using a single index:
main.r145 chars6 lines
To find out the dimensions of a matrix, you can use the dim()
function:
main.r65 chars3 lines
You can modify elements of a matrix using indexing:
main.r66 chars4 lines
main.r100 chars5 lines
gistlibby LogSnag