R Language-Data structure

Source: Internet
Author: User

1. Vectors

Vectors are one-dimensional arrays used to store numeric, character, or logical data, and a vector is created with function C ()

A <-C (1,2,5,6,4)

b <-C ("One", "one", "one", "three")

C <-C ("TRUE", "FALSE")

2. Matrix

A matrix is a two-dimensional array, except that each element has the same pattern, creating a matrix with the function matrix ()

Y <-Matrix (1:20, nrow = 5, Ncol = 4)

3. Arrays

Arrays are similar to matrices, but dimensions can be greater than 2, arrays are created with function array ()

DIM1 <-C ("A1", "A2")
DIM2 <-C ("B1", "B2", "B3")
DIM3 <-C ("C1", "C2", "C3", "C4")
Z <-Array (1:24, C (2, 3, 4), Dimnames=list (dim1, dim2, dim3))

4. Data frame

The concept of the data frame is more general than the matrix, the data frame is the most commonly processed data structure in R, and the function data.frame () is used to create

Patientid <-C (1, 2, 3, 4)
Age <-C (25, 34, 28, 52)
Diabetes <-C ("Type1", "Type2", "Type1", "Type1")
Status <-C ("Poor", "improved", "excellent", "Poor")
Patientdata <-Data.frame (Patientid, age, diabetes, status)

5. Factor

Category (nominal) variables and ordered categories (ordered) variables are called factors (factor) in R. Factor in R non-
Often important because it determines how data is analyzed and how it is visually presented.

Diabetes <-C ("Type1", "Type2", "Type1", "Type1")
Diabetes <-Factor (diabetes)

6. List

A list is the most complex of the data types of R. Generally, a list is some object (or ingredient,
component) of an ordered collection. Lists allow you to integrate several (possibly unrelated) objects into a single object name.

G <-"My first List"
H <-C (25, 26, 18, 39)
J <-Matrix (1:10, nrow=5)
K <-C ("One", "one", "one", "three")
MyList <-list (title=g, Ages=h, J, K)

R Language-Data structure

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.