R Language Basics-Arrays and lists

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.