Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########Vector Data Structure##############
- bag1=c(12,4,5,8,9)
- bag2=c(5,3,6,7)
- more<-bag1+bag2
- more
- #for vectorization the elements like bag1 and bag2 should have equal elements
- bag1=c(12,4,5,8)
- bag2=c(5,3,6,7)
- more<-bag1>=bag2
- more
- is.vector(more)
- c(1,2,3,4,5)<=3
- ##each and every element in c will be compare with every element in other ..this
- #is call as 'Broadcasting' as below.
- c(1,2,3,4,5)<=c(3,7)
- #Note: second first verctor should be in multiple of 2nd vector other wise
- #it will through "longer object length is not a multiple of shorter object length"...
- c(1,2,3,4,5,8)<=c(3,7)
- c(1,2,3,4,5,8)<=c(0)
- draw<-c(2,3,5,6,"K")
- draw
- class(draw)
- x=0:5
- x
- sum(x)
- class(sum)
- sum(x>1)
- sum(x[x>1])
- sum
- x=c(4,5,2,898,'A')
- sort(x)
- sort(x,decreasing = FALSE)
- sort(x,decreasing = TRUE)
- x<-c(3,2,5,1,6)
- seq(-3:-1)
- ######## Martrix DS #################
- matrix(1:6,nrow =2,ncol = 3)
- #Note:lenth of metric should be no.of rows divided by no.of Columns
- matrix(1:6,nrow =9,ncol = 7)
- cbind(1:3,1:3)
- rbind(c(1,2,3,4,5),c(11,22,33,44,55))
- cbind(c(1,2,3,4,5),c(11,22,33,44,55))
- matrix(1:6,ncol = 2)
- matrix(1:6,byrow = TRUE,nrow =2)
- m<-matrix(1:6,byrow = TRUE,nrow =2)
- m
- rbind(m,7:9)
- cbind(m,c(10:11))
- rownames(m)<-c("Row1","Row2")
- colnames(m)<-c("Col1","Col2","Col3")
- m
- ##or use dimnames attribute
- m<-matrix(1:6,byrow = TRUE,nrow = 2,dimnames = list(c("Row1","Row2"),
- c("Col1","Col2","Col3")))
- m
- is.matrix(m)
- is.vector(m)
- char<-matrix(LETTERS[1:6],nrow = 4,ncol = 3)
- char
- char<-matrix(LETTERS[1-2],nrow = 4,ncol = 3)
- char
- m<-matrix(sample(1:15,12),nrow = (3))
- m[1,3]
- m
- m[2,3]
- m[,3]
- m[3,]
- m[4]
- m[10]
Add Comment
Please, Sign In to add comment