Monthly Archives: August 2011
Formatting Character Strings in R
Formatting characters from lower to upper case: x<-c(“a”,”b”,”c”,”d”) toupper(x) From upper to lower case: x<-c(“A”,”B”,”C”) tolower(x) #all lower case Capitalize words in R: #install.packages(“Hmisc”) if you don’t have it already library(Hmisc) x<-c(“arizona”,”california”,”indiana”,”illinois”) capitalize(x) #[1] “Arizona” ”California” “Indiana” … Continue reading
Flat Tables
This is a nice little function that I learned about in John Verzani’s book. It makes table() output look a little nicer: data<-data.frame(x=rbinom(100,1,.3),y=rbinom(100,1,.5)) #Mock up a quick toy for the example ftable(table(data$x,data$y)) 0 1 0 40 29 1 13 18
Indexing Vectors and Data Frames in R
First create a vector containing some values, like this: x<-c(6,7,8,9,10,NA,NA) Now try the following: x[1] #gives the first value of x x[c(1,3,5)] … Continue reading