Saturday, 26 November 2016

15 cbind function in matrix R language

matrix operations

ram<-matrix(c(88,85,83,81,78,62,61,54,60,65,90,92,91,89,90),ncol=3)
colnames(ram)<-c("vijayawad","hyderabad","delhi")
rownames(ram)<-paste("11/",12:16,sep='')

c
rbind()

ndata<-matrix(c(98,78,66,55,99,66),nrow=1)
rownames(ndata)<-"11/17"
colnames(ndata)<-c(colnames(tem1),colnames(temp2))
rbind<-(cbind(temp1,temp2),ndata)


R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> temp2
Error: object 'temp2' not found
> temp2<-matrix(c(99,85,83,81,66,62,61,54,60,88,90,92,71,89,90),ncol=3)
> rownames(temp2)<-paste("Nov/",12:16,sep='')
> colnames(temp2)<-c("Chennai","Pune","Bengalore")
> temp1<-matrix(c(88,85,83,81,78,62,61,54,60,65,90,92,91,89,90),ncol=3)
> colnames(temp1)<-c("vijayawad","hyderabad","delhi")
> rownames(temp1)<-paste("Nov/",12:16,sep='')
> temp2
       Chennai Pune Bengalore
Nov/12      99   62        90
Nov/13      85   61        92
Nov/14      83   54        71
Nov/15      81   60        89
Nov/16      66   88        90
> temp1
       vijayawad hyderabad delhi
Nov/12        88        62    90
Nov/13        85        61    92
Nov/14        83        54    91
Nov/15        81        60    89
Nov/16        78        65    90
> cbind(temp1,temp2)
       vijayawad hyderabad delhi Chennai Pune
Nov/12        88        62    90      99   62
Nov/13        85        61    92      85   61
Nov/14        83        54    91      83   54
Nov/15        81        60    89      81   60
Nov/16        78        65    90      66   88
       Bengalore
Nov/12        90
Nov/13        92
Nov/14        71
Nov/15        89
Nov/16        90
> temp12<-cbind(temp1,temp2)
> temp12
       vijayawad hyderabad delhi Chennai Pune
Nov/12        88        62    90      99   62
Nov/13        85        61    92      85   61
Nov/14        83        54    91      83   54
Nov/15        81        60    89      81   60
Nov/16        78        65    90      66   88
       Bengalore
Nov/12        90
Nov/13        92
Nov/14        71
Nov/15        89
Nov/16        90
> newdata<-matrix(c(98,78,66,55,99,66),nrow=1)
> newdata
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]   98   78   66   55   99   66
> rnames(newdats)<-"Nov/17"
Error in rnames(newdats) <- "Nov/17" : object 'newdats' not found
> rnames(newdata)<-"Nov/17"
Error in rnames(newdata) <- "Nov/17" : could not find function "rnames<-"
> rname(newdata)<-"Nov/17"
Error in rname(newdata) <- "Nov/17" : could not find function "rname<-"
> rownames(newdata)<-"Nov/17"
> newdata
       [,1] [,2] [,3] [,4] [,5] [,6]
Nov/17   98   78   66   55   99   66
> colnames(newdata)<-c(colnames(temp12))
> newdata
       vijayawad hyderabad delhi Chennai Pune
Nov/17        98        78    66      55   99
       Bengalore
Nov/17        66
> rbind(temp12,newdata)
       vijayawad hyderabad delhi Chennai Pune
Nov/12        88        62    90      99   62
Nov/13        85        61    92      85   61
Nov/14        83        54    91      83   54
Nov/15        81        60    89      81   60
Nov/16        78        65    90      66   88
Nov/17        98        78    66      55   99
       Bengalore
Nov/12        90
Nov/13        92
Nov/14        71
Nov/15        89
Nov/16        90
Nov/17        66
> ftemp<-rbind(temp12,newdata)
> ftemp
       vijayawad hyderabad delhi Chennai Pune
Nov/12        88        62    90      99   62
Nov/13        85        61    92      85   61
Nov/14        83        54    91      83   54
Nov/15        81        60    89      81   60
Nov/16        78        65    90      66   88
Nov/17        98        78    66      55   99
       Bengalore
Nov/12        90
Nov/13        92
Nov/14        71
Nov/15        89
Nov/16        90
Nov/17        66
> c(ftemp)
 [1] 88 85 83 81 78 98 62 61 54 60 65 78 90 92 91
[16] 89 90 66 99 85 83 81 66 55 62 61 54 60 88 99
[31] 90 92 71 89 90 66
> length(ftemp)
[1] 36
>


No comments:

Post a Comment