Arrays (Array)
One-dimensional data is a vector, two-dimensional data is a matrix, the array is a direct generalization of vectors and matrices, is composed of three-dimensional or more than three-dimensional data. Array functions are arrays () and the syntax is: Array (DADTA, dim), where data must be of the same type. Dim is a vector of the lengths of each dimension. 1, produce a three-dimensional and four-dimensional array.
Example 1:xx <-Array (1:24, C (3, 4, 2)) #一个三维数组例2: yy <-Array (1:36, C (2, 3, 3, 2)) #一个四维数组 2, Dim () function converts vectors to arrays or matrices. Example 1:xx <-1:24; Dim (xx) <-C (3, 4, 2); XX #效果同array (1:24, C (3, 4, 2)) example 2:zz <-1:10; Dim (ZZ) <-C (2, 5); ZZ #效果同matrix (1:10, 2, 5) lists (list) vectors, matrices, and arrays of elements must be of the same type of data.
A data object needs to include different data types, which can take the form of a list.
To create a list () function, the syntax is: list (name1 = component1, name2 = Component2, ...). 1. Create a list example 1:xx <-rep (1:2, 3:4) yy <-C (' Mr A ', ' Mr B ', ' Mr C ', ' Mr D ', ' Mr E ', ' Mr D ', ' Mr F ') ZZ <-' discussion g Roup ' name.list <-list (group = XX, name = yy, decription = zz) #创建了一个名为 "Name.list" of name.list$n[name.list$g = = 2]lengt H (name.list) mode (name.list) names (name.list)
R Language Basics-Arrays and lists