1.Vector
All elements must be of the same type. For example, the following code creates 2 vectors.
name<-C("Mike.", "Lucy", "John")
Age<-C( -, -, -)
2.Array & Matrix
Matrix is a special kind of vector. Maxtrix is a vector with two additional attributes: the number of rows and columns.
>x<-Matrix(C(1,2,3,4),Nrow=2,Ncol=2)
>x
[,1] [,2]
[1,] 1 3
[2,] 2 4
Similar to Maxtrix, but arrays can be more than two-dimensional.
3.List
List can contain different types of elements
>y<-List(name="Mike.",Gender="M", Company="Programcreek")
>y
$name
[1] "Mike."
$gender
[1] "M"
$company
[1] "Programcreek"
4.Data Frame
The data frame is used to store the datasheet, which is a list of vectors that have equal lengths. For example, create a data frame with the following code.
>name<-C("Mike.", "Lucy", "John")
> Age<-C( -, -, -)
>Student<-C(TRUE,FALSE,TRUE)
>DF=Data.Frame(name, Age,Student)
>DF
Name Age Student
1 Mike -TRUE
2 Lucy -FALSE
3 John -TRUE
Vector, Array, list, and Data Frame in the R language