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"
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.
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.
sum() length() min max min(a,b) range() range()[1] range()[2] Mean
It is calculated by taking the sum of the values and dividing with the number of values in a data series.
mean() median() The median is the value separating the higher half of a data sample, a population, or a probability distribution, from the lower half. mad() In statistics, the median absolute deviation (MAD) is a robust measure of the variability of a univariate sample of quantitative data. It can also refer to the population parameter that is estimated by the MAD calculated from a sample. var() Variance
The variance is a numerical measure of how the data values is dispersed around the mean. In particular, the sample variance is defined as: sd() In statistics, the standard deviation (SD, also represented by the Greek letter sigma σ or the Latin letter s) is a measure that is used to quantify the amount of variation or dispersion of a set of data values.[ corelation a mutual relationship or connection between two or more things. cor(,) covariance is a measure of how much two random variables change together. cov() -------- table() table() function uses the cross-classifying factors to build a contingency table of the counts at each combination of factor levels.
R is a programming language and software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, surveys of data miners, and studies of scholarly literature databases show that R's popularity has increased substantially in recent years.https://en.wikipedia.org/wiki/R_(programming_language)