1. Prof. Neeraj Bhargava
Pramod Singh Rathore
Department of Computer Science
School of Engineering & System Sciences,
MDS University Ajmer, Rajasthan, India
1
Handle list, matrics,factors in R
3. Data types in R
3
Data types can be listed as
• Vectors
• Lists
• Matrices
• Data Frames
• Factors
4. How to handle list in R
4
a=c(2,3,4) output : 2 3 4
b=(“ab”,”bc”,”ef”)
d=c(True,False)
list(a,b,d)
lst_1=list(abd)
lst_1[[1]]
lst_1[[1]] [1]
Lst_1[[2]][3]=“xy” “ab” ”bc” ”xy”
5. How to handle matrices in R
5
matr=matrix(c(1,2,3,4,5,6),nrow=3,ncol=2,byrow=F) 1 4
matr 2 5
3 6
matr[,1]
matr[1,]
matr[1,1]
matr=cbind(matr,c(3,5,7)) ?cbind
matr=rbind(matr,c(3,5,7))
dimnames(matr)=list(c(”r1”,”r2”,”r3”,”r4”)c(“c1”,”c2”,”c3”,”c4”)
t(matr)
6. How to handle factors in R
6
y=factor(c(“first”,”second”,”first”,”first”,”third”)) 3level
z-=y[1:4]
Y[6]=“fourth”
levels(y)=c(level(y),”fourth”)
levels(y)
7. Assignment 1
What is data types in R?
Explain each data type with suitable example
7