Translate

Saturday, 26 November 2016

19 string functions in r Language

substr(,1,5)
nchar()
substr(,nchar()-8,nchar()
how to extract last 2 chars from vector
paste(a,b,sep='')
paste(a,b,"!",sep='')
paste(a,", ",b,"!",sep='')
paste(vector,", ",b,"!",sep='')
paste("x",1:10,sep=",")
grep("Ra",vector)
vector[grep("Ra",vector)]
grep("Ra",vector,value=TRUE)
grep("New",state.name,value=T)
strsplit(a,"   ")
sub("ram","nar",a)
gsub
----------

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.

[Workspace loaded from ~/.RData]

> vec <-c("ramesh","suresh","naresh","ganesh")
> v<-"hi how are you"
> V1<-"just"
> ?substr
> substr(v,1,5)
[1] "hi ho"
> substr(v,4,20)
[1] "how are you"
> substr(v,4,2)
[1] ""
> substr(v,4,9)
[1] "how ar"
> nchar(v)
[1] 14
> v
[1] "hi how are you"
> nchar(vec)
[1] 6 6 6 6
> vec
[1] "ramesh" "suresh" "naresh" "ganesh"
> v
[1] "hi how are you"
> substr(v,nchar(v)-3,nchar(v))
[1] " you"
> substr(v,nchar(v)-3,nchar(v))
[1] " you"
> substr(vec,1,2)
[1] "ra" "su" "na" "ga"
> paste(v,v1)
Error in paste(v, v1) : object 'v1' not found
> v1
Error: object 'v1' not found
> V1
[1] "just"
> paste(v,V1)
[1] "hi how are you just"
> paste(v,V1,sep=' / ')
[1] "hi how are you / just"
> paste(v,V1,"!",sep=' / ')
[1] "hi how are you / just / !"
> paste(v,V1,"Ram",sep=' / ')
[1] "hi how are you / just / Ram"
> paste(v,",",V1,"Ram",sep=' / ')
[1] "hi how are you / , / just / Ram"
>
> paste(V1,1:10)
 [1] "just 1"  "just 2"  "just 3"  "just 4"
 [5] "just 5"  "just 6"  "just 7"  "just 8"
 [9] "just 9"  "just 10"
> grep("ra",vec)
[1] 1
> grep("esh",vec)
[1] 1 2 3 4
> vesh
Error: object 'vesh' not found
> vec
[1] "ramesh" "suresh" "naresh" "ganesh"
> grep("a",vec)
[1] 1 3 4
> grep("a",vec,value=T)
[1] "ramesh" "naresh" "ganesh"
> state.name
 [1] "Alabama"        "Alaska"      
 [3] "Arizona"        "Arkansas"    
 [5] "California"     "Colorado"    
 [7] "Connecticut"    "Delaware"    
 [9] "Florida"        "Georgia"     
[11] "Hawaii"         "Idaho"       
[13] "Illinois"       "Indiana"     
[15] "Iowa"           "Kansas"      
[17] "Kentucky"       "Louisiana"   
[19] "Maine"          "Maryland"    
[21] "Massachusetts"  "Michigan"    
[23] "Minnesota"      "Mississippi" 
[25] "Missouri"       "Montana"     
[27] "Nebraska"       "Nevada"      
[29] "New Hampshire"  "New Jersey"  
[31] "New Mexico"     "New York"    
[33] "North Carolina" "North Dakota"
[35] "Ohio"           "Oklahoma"    
[37] "Oregon"         "Pennsylvania"
[39] "Rhode Island"   "South Carolina"
[41] "South Dakota"   "Tennessee"   
[43] "Texas"          "Utah"        
[45] "Vermont"        "Virginia"    
[47] "Washington"     "West Virginia"
[49] "Wisconsin"      "Wyoming"     
> grep("V",sate.name,value=T)
Error in grep("V", sate.name, value = T) : object 'sate.name' not found
> grep("V",state.name,value=T)
[1] "Vermont"       "Virginia"   
[3] "West Virginia"
> strsplit(v,"/")
[[1]]
[1] "hi how are you"

> strsplit(v,"      ")
[[1]]
[1] "hi how are you"

> strsplit(V1,"      ")
[[1]]
[1] "just"

> strsplit(V1,"/")
[[1]]
[1] "just"

> sub("a","k",vec)
[1] "rkmesh" "suresh" "nkresh" "gknesh"
> sub("s","z",vec)
[1] "ramezh" "zuresh" "narezh" "ganezh"
> gsub("s","z",vec)
[1] "ramezh" "zurezh" "narezh" "ganezh"

18 random numbers Functions in R language

random numbers
runif(1,0,10)
x<-matrix(100,0,1),ncol=10)
---
set.seed(2)
sample(1:10,5)
sample(x,5)
sample(0:1,100)
sample(0:1,100,replace=T)
sum(sample(0:1,100,replace=T))

state.name
sample(state.name,10)
--
s<-sample(1:5,1000,replace=T,prob=c(.2,.2,.2,.2,.2))
9059868766
venkat
table(s)
---
rnom(1)
-------------

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.

[Workspace loaded from ~/.RData]

> runif(1,1,10)
[1] 8.438811
> runif(1,1,10)
[1] 9.455057
> a= runif(1,1,10)
> a
[1] 1.533825
> a
[1] 1.533825
> a
[1] 1.533825
> a
[1] 1.533825
> a= runif(1,1,10)
> a
[1] 9.062645
> runif(4,1,10)
[1] 9.684915 7.945072 4.608548 8.766813
> runif(5,5,7)
[1] 6.302855 6.136968 6.119193 5.587079 6.033400
> an=matrix(runif(100,1,100),ncol=10)
> an
          [,1]     [,2]      [,3]     [,4]
 [1,] 17.75432 64.42554 33.544375 15.82550
 [2,] 85.59875 94.39768 63.713225 88.41076
 [3,] 83.64417 18.05964  2.511536 70.60304
 [4,] 78.92116 67.10841 64.811331 59.84145
 [5,] 89.59182 25.41236 69.217753 32.94199
 [6,] 97.07366 22.53897 77.627904 98.35555
 [7,] 16.68177 47.42317 51.392915 65.47258
 [8,] 38.17343 82.76507 60.983603 55.72940
 [9,] 19.47498 29.37258 31.161065 84.21841
[10,] 31.23285 74.66430 83.368968 29.16913
           [,5]     [,6]     [,7]     [,8]
 [1,] 86.260574 80.63066 30.94873 76.67941
 [2,] 61.753046 96.18675 20.12761 31.23936
 [3,] 21.795530 23.98979 33.31106 76.12806
 [4,] 24.627176 94.27216 34.70041 25.61517
 [5,]  7.915749 47.21915 37.51370 18.30664
 [6,] 87.660562 28.54266 66.19067 86.56617
 [7,]  8.286705 46.97633 11.86618 14.72213
 [8,]  4.057239 41.99362 27.68719 37.26553
 [9,] 30.313130 39.97871 61.40631 55.42384
[10,] 81.674761 13.22212 49.58386 76.71307
           [,9]    [,10]
 [1,] 98.641094 44.12686
 [2,] 45.728991 63.06460
 [3,] 52.971145 43.99829
 [4,] 59.973548 31.15030
 [5,] 34.073597 39.13850
 [6,]  1.354758 74.34744
 [7,] 41.567044 14.93894
 [8,] 56.111451 26.84879
 [9,] 55.458226 24.62272
[10,] 48.216264 34.75815
> runif(4,1,10)
[1] 3.045298 3.537711 1.005564 4.479743
> runif(4,1,10)
[1] 1.405773 2.423582 9.293291 9.501379
> set.seed(1)
> runif(4,1,10)
[1] 3.389578 4.349115 6.155680 9.173870
> runif(4,1,10)
[1] 2.815137 9.085507 9.502077 6.947180
> set.seed(1)
> runif(4,1,10)
[1] 3.389578 4.349115 6.155680 9.173870
> runif(4,1,10)
[1] 2.815137 9.085507 9.502077 6.947180
> runif(4,1,10)
[1] 6.662026 1.556076 2.853771 2.589011
> runif(4,1,10)
[1] 7.183206 4.456933 7.928573 5.479293
> set.seed(2)
> runif(4,1,10)
[1] 2.663940 7.321366 6.159937 2.512467
> runif(4,1,10)
[1] 9.494554 9.491275 2.162431 8.501039
> runif(4,1,10)
[1] 5.212167 5.949854 5.974067 3.150053
> set.seed(2)
> runif(4,1,10)
[1] 2.663940 7.321366 6.159937 2.512467
> runif(4,1,10)
[1] 9.494554 9.491275 2.162431 8.501039
> runif(4,1,10)
[1] 5.212167 5.949854 5.974067 3.150053
> sample(1:10,5)
[1] 8 2 4 6 7
> sample(1:60,5)
[1] 14 27  5 38 22
> sample(1:60,20)
 [1] 51  9 21 28 59 20 52  8  1 56 41 43 25 30 39
[16] 13 47  7 42 45
> sample(1:60,5)
[1]  7 10 55 46 58
> x<-1:60
> x
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
[16] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[31] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
[46] 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
> sample(x,5)
[1] 21 30 48  1 57
> sample(0:1,5)
Error in sample.int(length(x), size, replace, prob) :
  cannot take a sample larger than the population when 'replace = FALSE'
> sample(0:2,5)
Error in sample.int(length(x), size, replace, prob) :
  cannot take a sample larger than the population when 'replace = FALSE'
> sample(0:2,5,replace=T)
[1] 2 2 0 2 2
> sample(0:2,5,replace=T)
[1] 2 1 2 2 2
> sample(0:2,5,replace=F)
Error in sample.int(length(x), size, replace, prob) :
  cannot take a sample larger than the population when 'replace = FALSE'
> sample(0:1,100,replace=T)
  [1] 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0
 [23] 0 1 1 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1
 [45] 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 0 1 1 0 1 1 0
 [67] 1 0 0 1 0 1 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0
 [89] 0 0 1 0 1 0 1 0 0 0 1 1
> sum(sample(0:1,100,replace=T))
[1] 48
> table(sample(0:1,100,replace=T))

 0  1
51 49
> table(sample(0:1,100,replace=T))

 0  1
45 55
> table(sample(0:1,100,replace=T))

 0  1
47 53
> table(sample(0:1,100,replace=T))

 0  1
49 51
> state.name
 [1] "Alabama"        "Alaska"      
 [3] "Arizona"        "Arkansas"    
 [5] "California"     "Colorado"    
 [7] "Connecticut"    "Delaware"    
 [9] "Florida"        "Georgia"     
[11] "Hawaii"         "Idaho"       
[13] "Illinois"       "Indiana"     
[15] "Iowa"           "Kansas"      
[17] "Kentucky"       "Louisiana"   
[19] "Maine"          "Maryland"    
[21] "Massachusetts"  "Michigan"    
[23] "Minnesota"      "Mississippi" 
[25] "Missouri"       "Montana"     
[27] "Nebraska"       "Nevada"      
[29] "New Hampshire"  "New Jersey"  
[31] "New Mexico"     "New York"    
[33] "North Carolina" "North Dakota"
[35] "Ohio"           "Oklahoma"    
[37] "Oregon"         "Pennsylvania"
[39] "Rhode Island"   "South Carolina"
[41] "South Dakota"   "Tennessee"   
[43] "Texas"          "Utah"        
[45] "Vermont"        "Virginia"    
[47] "Washington"     "West Virginia"
[49] "Wisconsin"      "Wyoming"     
> sample(state.name,5)
[1] "Mississippi"   "Virginia"   
[3] "Massachusetts" "Alaska"     
[5] "Oklahoma"   
> sample(0:1,100,replace=T)
  [1] 0 1 0 0 0 1 0 0 1 1 1 1 0 1 0 1 0 0 0 1 1 1
 [23] 1 0 0 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 0 1
 [45] 0 0 0 1 0 1 1 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0
 [67] 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0 0 0 1 1
 [89] 0 1 0 1 1 0 0 0 1 1 1 0
> sample(0:5,100,replace=T)
  [1] 2 5 3 0 1 3 2 2 0 5 4 4 2 3 2 5 3 5 0 4 0 2
 [23] 1 3 4 0 0 5 1 3 4 4 4 2 3 0 1 0 5 1 3 4 1 2
 [45] 2 1 5 0 2 5 3 3 5 3 0 0 0 3 0 0 0 2 4 0 0 5
 [67] 3 0 3 5 5 3 3 4 3 0 0 5 5 4 0 5 2 4 0 4 0 4
 [89] 1 0 5 3 2 0 2 2 5 0 5 5
> table(sample(0:5,100,replace=T))

 0  1  2  3  4  5
19 16 17 21 10 17
> sample(0:5,100,replace=T,prob=c(.2,.2,.2,.2,.2))
Error in sample.int(length(x), size, replace, prob) :
  incorrect number of probabilities
> sample(1:5,100,replace=T,prob=c(.2,.2,.2,.2,.2))
  [1] 1 1 3 2 4 2 5 4 5 2 1 2 5 1 2 4 4 1 4 2 5 5
 [23] 4 4 1 2 3 2 3 4 1 4 2 3 2 5 4 3 2 3 1 4 3 1
 [45] 3 3 3 1 2 2 2 1 2 2 5 4 3 2 5 1 3 5 1 5 3 1
 [67] 1 5 5 4 2 5 2 4 5 5 5 5 4 4 1 4 1 5 3 1 5 4
 [89] 2 1 4 4 2 2 2 3 3 1 4 1
> a=sample(1:5,100,replace=T,prob=c(.2,.2,.2,.2,.2))
> table(a)
a
 1  2  3  4  5
31 17 22 15 15
> table(a)
a
 1  2  3  4  5
31 17 22 15 15
> a=sample(1:5,100,replace=T,prob=c(.2,.2,.2,.2,.2))
> a
  [1] 2 4 2 3 5 2 5 3 3 4 3 1 4 3 2 5 4 2 1 4 1 4
 [23] 1 2 3 5 4 4 4 2 4 2 2 2 3 4 4 2 4 3 5 1 3 1
 [45] 1 4 1 1 1 5 3 2 3 3 1 2 1 5 5 5 5 4 4 4 5 1
 [67] 2 2 1 3 5 5 4 3 5 5 5 4 1 4 3 1 2 5 1 3 2 2
 [89] 5 1 5 2 1 4 1 5 2 2 1 1
> table(a)
a
 1  2  3  4  5
22 21 16 21 20
> a=sample(1:5,100,replace=T,prob=c(.6,.1,.1,.1,.1))
> a
  [1] 1 1 5 1 1 2 1 1 4 1 1 5 3 1 1 1 1 1 1 1 1 1
 [23] 1 4 3 1 5 3 2 1 1 1 5 2 1 2 1 3 2 1 1 2 2 1
 [45] 1 1 3 1 2 1 1 1 1 1 5 2 1 2 4 1 1 5 1 1 2 4
 [67] 1 1 1 1 1 5 1 1 1 3 1 1 3 2 3 1 1 1 1 1 1 1
 [89] 1 1 1 1 1 1 1 1 1 1 1 1
> table(a)
a
 1  2  3  4  5
69 12  8  4  7
> a=sample(1:5,100,replace=T,prob=c(.2,.4,.1,.1,.1))
> table(a)
a
 1  2  3  4  5
23 41  7 15 14



17 matrics statistics functions In R language


matrics statistics
min()
max()
range()
sd()
rowMeans()
colMeans()
apply(,2,FUN=sd)
cor()
table()
summary()
summary(t())
-----------------
> View(newdata)
> View(temp1)
> 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
> 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
> 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
> View(ftemp)
> min(ftemp)
[1] 54
> max(ftemp)
[1] 99
> range(ftemp)
[1] 54 99
> range(ftemp)[1]
[1] 54
> range(ftemp)[2]
[1] 99
> sd(ftemp)
[1] 14.23778
> rowMeans(ftemp)
  Nov/12   Nov/13   Nov/14   Nov/15   Nov/16
81.83333 79.33333 72.66667 76.66667 79.50000
  Nov/17
77.00000
> colMeans(ftemp)
vijayawad hyderabad     delhi   Chennai
 85.50000  63.33333  86.33333  78.16667
     Pune Bengalore
 70.66667  83.00000
> sd(ftemp)
[1] 14.23778
> apply(ftemp,2,sd)
vijayawad hyderabad     delhi   Chennai
 7.007139  8.041559 10.013324 15.471479
     Pune Bengalore
18.239152 11.384200
> apply(ftemp,1,sd)
  Nov/12   Nov/13   Nov/14   Nov/15   Nov/16
15.82930 14.54189 15.80717 13.39652 11.72604
  Nov/17
18.17691
> cor(ftemp)
           vijayawad  hyderabad      delhi
vijayawad  1.0000000  0.7347158 -0.8522797
hyderabad  0.7347158  1.0000000 -0.9007808
delhi     -0.8522797 -0.9007808  1.0000000
Chennai   -0.3219236 -0.7367826  0.7380108
Pune       0.4647732  0.9131535 -0.7723986
Bengalore -0.6242896 -0.3845032  0.7158291
             Chennai       Pune  Bengalore
vijayawad -0.3219236  0.4647732 -0.6242896
hyderabad -0.7367826  0.9131535 -0.3845032
delhi      0.7380108 -0.7723986  0.7158291
Chennai    1.0000000 -0.8679834  0.5393731
Pune      -0.8679834  1.0000000 -0.3583157
Bengalore  0.5393731 -0.3583157  1.0000000
> table(ftemp)
ftemp
54 55 60 61 62 65 66 71 78 81 83 85 88 89 90 91
 2  1  2  2  2  1  3  1  2  2  2  2  2  2  4  1
92 98 99
 2  1  2
> summary(ftemp)
   vijayawad       hyderabad         delhi    
 Min.   :78.00   Min.   :54.00   Min.   :66.00
 1st Qu.:81.50   1st Qu.:60.25   1st Qu.:89.25
 Median :84.00   Median :61.50   Median :90.00
 Mean   :85.50   Mean   :63.33   Mean   :86.33
 3rd Qu.:87.25   3rd Qu.:64.25   3rd Qu.:90.75
 Max.   :98.00   Max.   :78.00   Max.   :92.00
    Chennai           Pune         Bengalore 
 Min.   :55.00   Min.   :54.00   Min.   :66.0
 1st Qu.:69.75   1st Qu.:60.25   1st Qu.:75.5
 Median :82.00   Median :61.50   Median :89.5
 Mean   :78.17   Mean   :70.67   Mean   :83.0
 3rd Qu.:84.50   3rd Qu.:81.50   3rd Qu.:90.0
 Max.   :99.00   Max.   :99.00   Max.   :92.0
> summary(t(ftemp)
+ )
     Nov/12          Nov/13          Nov/14   
 Min.   :62.00   Min.   :61.00   Min.   :54.00
 1st Qu.:68.50   1st Qu.:67.00   1st Qu.:58.25
 Median :89.00   Median :85.00   Median :77.00
 Mean   :81.83   Mean   :79.33   Mean   :72.67
 3rd Qu.:90.00   3rd Qu.:90.25   3rd Qu.:83.00
 Max.   :99.00   Max.   :92.00   Max.   :91.00
     Nov/15          Nov/16         Nov/17
 Min.   :60.00   Min.   :65.0   Min.   :55
 1st Qu.:65.25   1st Qu.:69.0   1st Qu.:66
 Median :81.00   Median :83.0   Median :72
 Mean   :76.67   Mean   :79.5   Mean   :77
 3rd Qu.:87.00   3rd Qu.:89.5   3rd Qu.:93
 Max.   :89.00   Max.   :90.0   Max.   :99
>

16 rbind function in matrix R language

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
>