CRM Cheat Sheet
CRM Cheat Sheet
R Reference Sheet
Eric Pitman Annual Summer Workshop in Computational Science
Summer 2013
R Reference Sheet
---------------------------------------------------------------------RStudio Tips-------------------------------------------------------------------
To see your history (commands you have already issued), click the history pane or
simply click the up arrow on your keyboard while on the command line
To change the relative sizes of each window, hover the mouse over the window border
until appears.
Use Heading=Yes
Load command:
> drop=read.csv(drop.csv)
-----------------------------------------------------------------Common functions--------------------------------------------------------------
-----------------------------------------------------------Conditionals/Function Calls---------------------------------------------------------
if (condition is true) {
# do something
functionName =function(inputs) {
---------------- # do something
----------------------------------------------------------------Common Plots--------------------------------------------------------------------
example scatterplot:
data(diamonds, package=ggplot2)
plot( formula=price~carat,
data=diamonds,
col=darkblue,
pch=20,
example barplot:
data(diamonds, package=ggplot2)
ideal=diamonds[diamonds$cut=="Ideal","color"]
barplot( table(ideal),
xlab="color",
ylab="count",
col="hotpink" )
R Reference Sheet
example histogram:
data(Cars, package=MASS)
hist( Cars93$RPM,
breaks = 4,
xlab="RPM",
col="red"
data(Cars, package=MASS)
plot( density(Cars93$RPM,bw=200),
xlab="RPM",
col="blue"
example boxplot:
boxplot(formula=mpg~gear,
data=mtcars,
xlab="Number of Gears",
col=c("red","green","blue")
)
R Reference Sheet
library(pROC)
print.auc = TRUE,
print.auc.col="red",
print.thres=TRUE,
print.thres.col="blue",
grid=TRUE
title = "---",
fill = c("Color.1","Color.2",etc.)
*N.B. There are practically endless possibilities for making graphs and plots pretty!! Play around and find out how!!
R Reference Sheet
#--------------------------------------------------------------Apply Family---------------------------------------------------------
# There are many types of the function apply, but for our purposes, we will only be using sapply.
sapply
The apply() family of functions can be used to call some other function multiple times on a dataset, with several
different arguments. sapply() returns a vector or matrix result. You can use sapply() on a native R function, or
on a function you wrote yourself.
EXAMPLE: