##R Cheat Sheet
Turn off scientific notation except for very large numbers
options(scipen=20)
###Data transformation
Make a new date column from a column with datetime data stored as a string
data$date <- as.POSIXct(data$date, format='%m/%d/%Y')
or
data$date <- as.Date(data$date, format="%m/%d/%y")
Convert a column containing a string of UNIX time to a date
date[, {column number}] <- as.Date(as.POSIXct(data[, {column number}], origin='1970-01-01'))
Group and sum a column into a new dataframe
# Assuming a following data frame structured as data[store, revenue, date]
new <- aggregate(data$revenue, by=list(date=data$date), FUN=sum)
Subset a dataframe by a date range
subset <- subset(data, date >= '2000-01-01' & date <= '2010-01-01')
Subset a dataframe by regex matching
subset <- subset(data, grepl("regex", data[[column number]]))
Rename dataframe column names
colnames(date) <- c("column 1 name", "column 2 name", "column 3 name")
Sort a dataframe
attach(data)
sorted <- data[order(data$sort_column) , ]
# or, in decending order
sorted <- data[order(-data$sort_column) , ]
detach(data)
###Analysis
Generate a table of frequencies for the values in a single column
count_of_value <- as.data.frame(table(data["column"]))
###Graphing
Make a timeseries line chart by group
# Assuming a following data frame structured as data[store, revenue, date]
# and library("ggplot2")
qplot(date, revenue, data=data, group=store, geom="line")
Turn off axes, and add your own customized verions
plot(data, axes=FALSE)
# See ?axis for options
axis(...)
###Mapping
Amanda Cox's R Training from #NICAR13