|
30秒注册登陆,可查看更多信息,结交更多好友,享用更多功能,轻松玩转论坛,白白手拉手欢迎您的加入!
您需要 登录 才可以下载或查看,没有账号?注册新成员
x
[size=11.000000pt]In addition to data frames, R provides other structures that store values in a tabularform. A [size=11.000000pt]matrix [size=11.000000pt]is a data structure that represents a two-dimensional table withrows and columns of data. Like vectors, R matrixes can contain any one type ofdata, although they are most often used for mathematical operati** and, therefore,typically store only numeric data.(除了数据框之外,R还提供了其他的数据结构用于存储表格状的数据。例如矩阵。矩阵是一个二维的数据结构,矩阵能存储任何的数据类型,但是大部分我们使用矩阵是用于数**算,所以我们主要还是使用它来存储数字类型的)
To create a matrix, simply supply a vector of data to the matrix() function alongwith a parameter specifying the number of rows (nrow) or number of columns (ncol).For example, to create a 2 x 2 matrix storing the numbers one through four, we canuse the nrow parameter to request the data to be divided into two rows使用matrix函数来创建矩阵。参数nrows指定行数,ncol指定列数,见图1)[size=11.000000pt]
[size=11.000000pt]You will notice that R loaded the rst column of the matrix rst before loading the[size=11.000000pt]second column. This is called [size=11.000000pt]column-major order[size=11.000000pt], and is R's default method forloading matrices.(注意图中数据的排列,是先给第一列赋值,在给第二列赋值。这是R默认的赋值方式即按列的顺序赋值)
As with data frames, values in matrixes can be extracted using [row, column]notation. For instance, m[1, 1] will return the value 1 and m[3, 2] will extract 6from the m matrix. Additionally, entire rows or columns can be requested和数据框类似,我们也可以通过[行号,列号]来获取矩阵中的数据,见图2)[size=11.000000pt]
[size=11.000000pt]Closely related to the matrix structure is the [size=11.000000pt]array[size=11.000000pt], which is a multidimensionaltable of data. Where a matrix has rows and columns of values, an array has rows,columns, and any number of additional layers of values. Although we will beoccasionally using matrixes in the upcoming chapters, the use of arrays is outsidethe scope of this book.(数组和矩阵很相像.数组是多维的,也有多行和多列,在以后的章节我们将很少的使用矩阵,数组的使用则不再本书的讨论范围)
图1
图2
|
|