RCode from Devin Flawd Place to list common codes and explanations for worksheet Extra stuff Environment help() # type any function to pull up the documentation install.packages() # install an R package, can also use Tools -> Install Packages? on the menu bar library(), require() # enable or activate R packages that have already been installed rm() # remove an object ls() # list all objects currently stored in the R environment View() # open a separate tab to view a data frame as a spreadsheet names() # retrieve or assign names to an object na.rm() # remove NA values from an object str() # return the string of an object (class type and values) class() # return the class type of an object Input and Display DATAFRAME <- read.delim("C:/R/Examples/Length.txt", sep=??, header=TRUE) # DATAFRAME <- read.csv(file.choose()) # newframe <- x$columnname # assign a certain column (?columnname?) from data frame ?x? to a new data frame *Personally I never use attach()/detach()* Vectors and Matrices a <- c(0,1,2) # assign (c)oncatenated objects to ?a? as a vector (in this case, of length 3) > a > 0 1 2 b <- c(3:5) # assign (c)oncatenated all objects between first and last objects specified (x:y) > b > 3 4 5 c <- c(a, b) # assign (c)oncatenated objects to ?c? as a vector of all objects > c > 0 1 2 3 4 5 cbind() # bind objects by column > cbind(a, b) > a b 0 3 1 4 2 5 rbind() # bind objects by row > rbind(a, b) > a 0 1 2 b 3 4 5 Basic Functions mean() # return the mean of an object var() # return the variance of an object sd() # return the standard deviation of an object sum() # return the sum of all values or objects tapply() summary() d = density p = cumulative distribution function r = random q = quantile Probability dbinom() pbinom() qbinom() rbinom() binom.test() pnorm() rnorm() qnorm() dnorm() Plots plot() barplot() boxplot() hist() lag.plot() par() qqnorm() qqline() resid() fitted() P-values qt() pt() rt() dt() pchisq() qchisq() chisq.test() Modeling and Stat Tests lm() t.test() anova()