rstudio创建矩阵
Matrices are a very important concept in R programming, mostly used for statistics and data manipulation. Where vectors are a set of values stored across a single dimension, matrices are collections of stored values across multiple dimensions. Matrices can be simply thought of as a number of vectors that are saved and can be manipulated together. R has several powerful functions for this.
矩阵是R编程中非常重要的概念,主要用于统计和数据操作。 向量是在单个维度上存储的一组值,而矩阵是在多个维度上存储的值的集合。 可以简单地将矩阵视为保存并可以一起操纵的多个向量。 R为此具有几个强大的功能。
在R编程中创建矩阵 (Creating Matrices in R Programming)
The subscripting in matrices begins with 1. Therefore, [1,1] represents the element corresponding to the first-row first column, [1,2] represents the element at the first row and second column and so on.
矩阵的下标从1开始。因此,[1,1]代表与第一行第一列对应的元素,[1,2]代表在第一行和第二列的元素,依此类推。
Matrices in R are created in the following manner:
以下列方式创建R中的矩阵:
mymat <- matrix(c(2,4,6,8),ncol=2,nrow=2)
The first argument we pass to the matrix creation is a vector of values to populate the matrix with. Then we need to specify the no. of columns and rows, as indicated by the ncol
and nrow
arguments. The number of elements in the vec