Data Structure in R language, data structure in R Language

Source: Internet
Author: User

Data Structure in R language, data structure in R Language

The R language is still a bit old, and the data structure is not as easy as in Python. Below is a brief summary of several data structures commonly used in the R language.


Vectors in R can be understood as one-dimensional arrays. Each element must have the same mode and can be created using c (x: y), such as x <-c ).


The matrix in R can be understood as a two-dimensional array. Each element must have the same mode and be created using matrix. The form of matrix is:

Matrix (vector, nrow = number_of_rows, ncol = number_of_columns, byrow = logical_value, dimnames = list (rownames, colnames, ncol indicates the number of columns. byrow is a Boolean vector that indicates whether to fill the data based on rows. By default, dimnames indicates an optional row and column name.


Arrays in R are created using arrays. Unlike vectors or matrices, Arrays can be multidimensional. The data in array is also in the same mode. The array Function is as follows:

Array (vector, dimensions, dimnames), where vector contains elements in the array. dimensions is a vector that specifies the size of each dimension of the array, and dimnames is the name of each dimension specified by a list.

Data box:

A data box is a common data storage method for data analysis. It corresponds to a record for each row of the database, and each column corresponds to a field. The data box uses data. frame (name1 = col1, name2 = col2 ,...) create, note that the column is dominant.


The list in R is similar to dict in Python. It is behavior-dominated to create with list (name1 = object1, name2 = object2 ,...).

Computer Science Series: Data Mining and R Language

"" First briefly introduces the basic knowledge of R Software (installation, R Data Structure, R programming, R input and output ). Then, we will introduce the data mining technology through four actual data mining cases (algae frequency prediction, securities trend prediction and transaction system simulation, transaction fraud prediction, and micro-array data classification. These four cases cover common data mining technologies, from unsupervised data mining technology, supervised data mining technology to semi-supervised data mining technology. The book organizes content based on actual problems, solutions, and discussions on solutions. The context is clear and the chapters are self-contained. You can start from the beginning to the end, or learn based on your needs to find your own solutions to actual problems.
This book does not aim to introduce all aspects of data mining. Many existing books cover the field of data mining. We use several cases to introduce the data mining capabilities of R to readers. Obviously, these cases cannot represent all the data mining problems we encounter in the real world. At the same time, the solution we provided is not the most complete solution.

How to merge two groups of data in the R Language

If the null part is represented by NA, it can be encoded as follows:
Assume that the first group of data is a1 and the second group of data is a2. Their rows are consistent!
Index <-is. na (a1) a1 [index] <-a2 [index] # here is a examplea1 <-c (1, NA, 3, NA, 5, 6, NA, 8, 9, 10) a1a2 <-1: 10a2length (a1) length (a2) index <-is. na (a1) a1 [index] <-a2 [index] a1 result:

I don't know if you want the result ~
If you can provide a data structure, I may be able to provide more specific methods!


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: 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.