-R object
In R the variables are not declared as data type but as objects. The data type of the R-object becomes the data type of the variable.
There are many types of R-objects. The frequently used ones are Vectors, Matrices, Arrays, Data frame, List, and Factor
Vectors:
A vector is a sequence of same datatype elements
a <-c(1,2,3,4.9,10,2,4) # numeric
vectorb <-c("one","two","three") # character
vectorc <-c(TRUE,FALSE) #logical vectora;b;cGet the position of the elements using vector[c(postion)]
b[c(1,2)] # 1st and 2nd elements of vector bMatrix:
A matrix is two-dimensional vector. The matrix elements must be of the same data type
c<- matrix(
c(1:6), # the data elements
nrow=2, # number of rows
ncol=3, # number of columns
byrow = TRUE) # fill matrix by rows
c # print the matrix
#####################
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6Array:
An array is matrix with more than 2-dimensions (n-matrix)
Data frame:
A data frame is tabular store system. The column must be same length. Data frame used as the by most of R's modeling software
List:
A list is a vector containing other objects. Every object can be different length and datatype
Factor and Order
Factor create a distinct value from the data and ordered() create a ordinal structure of the data (based on alphabetical or numerical value)
Last updated