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