\documentclass[11pt,twocolumn]{article}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{alltt}
\usepackage{hyperref}

\hypersetup{colorlinks=true}

\textheight = 9.5 in
\oddsidemargin = 0.0 in
\evensidemargin = 0.0 in
\topmargin = 0.0 in
\headheight = 0.0 in
\headsep = 0.0 in
\parskip = 1pt
\parindent = 0.0in

%\setlength{\hoffset}{-65pt}
%\setlength{\voffset}{-65pt}
\newcommand{\ttnrbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttitbf}[1]{\textnormal{\textbf{#1}}}
\newcommand{\ttit}[1]{\textit{#1}}
\newcommand{\sSecBox}[1]{\begin{minipage}{3in}\begin{alltt}{\small\textrm{\textbf{#1}}}}
\newcommand{\eSecBox}{\end{alltt}\end{minipage} \\ \rule{0pt}{1pt}\hrule}

\newcommand{\aSymb}{\ttit{symb}}
\newcommand{\aBody}{\ttit{body}}
\newcommand{\aVal}{\ttit{value}}
\newcommand{\aVec}{\ttit{vector}}
\newcommand{\aArr}{\ttit{array}}
\newcommand{\aList}{\ttit{list}}
\newcommand{\aForm}{\ttit{form}}
\newcommand{\aInt}{\ttit{int}}
\newcommand{\aArg}{\ttit{arg}}
\newcommand{\aFunc}{\ttit{func}}
\newcommand{\aTest}{\ttit{test}}
\newcommand{\aString}{\ttit{string}}
\newcommand{\aName}{\ttit{name}}
\newcommand{\aPair}{\ttit{pair}}
\newcommand{\aSeq}{\ttit{seq}}

\newcommand{\nSeq}[1]{\ttit{seq#1}}
\newcommand{\nArg}[1]{\ttit{arg#1}}
\newcommand{\nSymb}[1]{\ttit{symb#1}}
\newcommand{\nBody}[1]{\ttit{body#1}}
\newcommand{\nVal}[1]{\ttit{value#1}}
\newcommand{\nList}[1]{\ttit{list#1}}
\newcommand{\nForm}[1]{\ttit{form#1}}
\newcommand{\nTest}[1]{\ttit{test#1}}
\newcommand{\nString}[1]{\ttit{string#1}}
\newcommand{\nInt}[1]{\ttit{int#1}}

\newcommand{\blt}{\makebox[2ex]{\(\bullet\)}}
\newcommand{\bsp}{\makebox[2ex]{}}

\newcommand{\dfa}{\makebox[2ex]{\(\mapsto\)}}    % Define Arrow

\begin{document}
\pagestyle{empty}

\fbox{{\parbox[b]{2in}{\huge \bf R \& S-Plus \\ \tiny \copyright 2000-2016 Mitch Richling \url{https://www.mitchr.me}  \\ Last Updated 2016-07-09}}}
\tiny

\sSecBox{Help}
\blt help(topic, ...) # Get help on various topics
\blt options(htmlhelp=FALSE/TRUE)  # Use terminal or browser
\blt help.search(pattern, ...)
\blt library(help=\ttit{libName})
\eSecBox

\sSecBox{Vector Indexing}
\textsc{NOTE: } a<-1:10; names(a)<-letters(a)
\textsc{NOTE: Subvectors have element names too)}
\blt a[2]                   \dfa 2
\blt a[-2]                  \dfa 1 3 4 5 6 7 8 9 0
\blt a[c(1,3,4)]            \dfa 1 3 4
\blt a[1:4]                 \dfa 1 2 3 4
\blt a[-c(1,3,4)]           \dfa 2 5 6 7 8 9 0
\blt a[c(T,F,T,rep(F, 7))]  \dfa 1 3
\blt a[c(T,F)]              \dfa 1 3 5 7 9 \textsc{(NOTE: Index vector is recycled)}
\blt a["a"]                 \dfa 1
\blt a[c("a","b")]          \dfa 1 2
\eSecBox

\sSecBox{Matrix (2D Array) Indexing}
\textsc{NOTE: } a<-matrix(1:25, nrow=5) # Could use ncol too!
\textsc{NOTE: } rownames(a) <- letters[1:5]; colnames(a) <- letters[22:26]
\textsc{NOTE: subarrays/vectors will have row/col names too}
\blt a[2,]                  \dfa Row 2                      \textsc{a vector}
\blt a[,2]                  \dfa Column 2                   \textsc{a vector}
\blt a['b',]                \dfa Row 2                      \textsc{a vector}
\blt a[,'w']                \dfa Column 2                   \textsc{a vector}
\blt a[,-2]                 \dfa All BUT column 2           \textsc{a matrix}
\blt a[-2,]                 \dfa All BUT row 2              \textsc{a matrix}
\blt a[c(1,3,4),]           \dfa Row 1, 3, \& 4              \textsc{a matrix}
\blt a[,c(1,3,4)]           \dfa Column 1, 3, \& 4           \textsc{a matrix}
\blt a[-c(1,3,4),]          \dfa All BUT Row 1, 3, \& 4      \textsc{a matrix}
\blt a[,-c(1,3,4)]          \dfa All BUT Column 1, 3, \& 4   \textsc{a matrix}
\blt a[1:6]                 \dfa 1 2 3 4 5 6                \textsc{a vector}
\bsp \textsc{   NOTE: Indexed as a column order vector}
\eSecBox

\sSecBox{List Indexing}
\textsc{NOTE: } a<-list(1:10); names(a)<-letters(1:10);
\textsc{NOTE:   All lists/vectors have element names}
\blt a[[2]]                 \dfa 2                          \textsc{a vector}
\blt a[["b"]]               \dfa 2                          \textsc{a vector}
\blt a$b                    \dfa 2                          \textsc{a vector}
\blt a$"b"                  \dfa 2                          \textsc{a vector}
\blt a[-2]                  \dfa 1 3 4 5 6 7 8 9 0          \textsc{a list}
\blt a[c(1,3,4)]            \dfa 1 3 4                      \textsc{a list}
\blt a[c(-1,-3,-4)]         \dfa 2 5 6 7 8 9 0              \textsc{a list}
\blt a[c(T,F,T,rep(F, 7))]  \dfa 1 3                        \textsc{a list}
\blt a["a"]                 \dfa 1                          \textsc{a list}
\blt a[c("a","b")]          \dfa 1 2                        \textsc{a list} 
\eSecBox

\sSecBox{data.frames}
\textsc{NOTE: data.frames are basically a list of (column) vectors.}
\blt Indexing may be done vector-style, list-style, or matrix-style
\bsp \blt list-style: Requested column (vectors or factors) is returned
\bsp \blt matrix: new sub-data frame is returned just like with a matrix
\bsp \blt vector: new data frame with the given columns is returned
\blt Applying many functions, like sum or mean, to a data.frame will
\bsp result in the functions being applied to each column.
\eSecBox

\sSecBox{Formulas}
\textsc{NOTE: The symbols in formulas can be the names of global variables}
\textsc{      or the names of columns in a given data.frame.  The interpretation}
\textsc{      of formulas is context sensitive.}
\blt General form to represent variable dependency relations:
\bsp dependent variable ~ independent variable.
\bsp Examples: plot(y~x, data=aFrame)  <=> plot(aFrame$x, aFrame$y)
\bsp           lm(y~x, data=aFrame)
\eSecBox

\sSecBox{Factors}
\blt Indexed vector-style, a sub-factor is returned with the given elements
\bsp \blt The levels are the SAME even if the sub-factor doesn't need them all 
\blt as.numeric(f) returns the numbers that code to each level
\blt as.vector(f) returns the original data as a character vector
\bsp \blt Follow with as.numeric, as.POSIXct, etc... to transform type
\eSecBox

\sSecBox{Apply}
\blt lapply/sapply  
Apply function to ONE list/vector
\blt mapply         Apply function to SEVERAL vectors & lists
\bsp \bsp Ex: mapply(sum, 1:4, 4:1) \dfa c(5,5,5,5)
\blt apply          Apply function to array slices
\bsp \bsp Ex: apply(b, 1, sum) \dfa rowSums(b)
\bsp \bsp Ex: apply(b, 2, sum) \dfa colSums(b)
\eSecBox

\sSecBox{Ragged Apply}
\blt tapply         Apply function to 'ragged' array
\bsp Breaks array into factor level groups, and applys function to groups
\bsp \bsp Ex: tapply(d$age, d$sex, sum)     # Total wt by sex
\bsp \bsp Ex: tapply(d$age, d$sex, length)  # Number of M/F in sample
\blt split          Break object into list of groups
\blt by             tapply for data.frames
\blt aggregate      Apply function to groups in data.frame
\eSecBox

\sSecBox{Time \& Date}
\blt as.POSIXct     Convert to UNIX-like time integer
\bsp                Use 'origin' when converting integers
\bsp \bsp Ex:  as.POSIXct(\textsc{unix_date}, origin='1970-01-01') 
\blt as.POSIXlt     Convert to UNIX-like time components
\bsp                sec,min,hour,mday,mon,year,wday,yday,isdst
\blt strftime       Convert time types to strings.
\blt strptime       Convert strings into valid POSIXlt
\bsp \bsp Format strings (strftime & strptime):
\bsp \blt %a  Abbreviated weekday name.      \blt %A  Full weekday name
\bsp \blt %b  Abbreviated month name.        \blt %B  Full month name.
\bsp \blt %d  Day of the month (01-31).      \blt %j  Day of year (001-366).
\bsp \blt %H  Hours  (00-23).                \blt %I  Hours  (01-12).
\bsp \blt %y  Year  (00-99).                 \blt %Y  Year with century.
\bsp \blt %M  Minute (00-59).                \blt %S  Second (00-61)
\bsp \blt %p  AM/PM indicator in the locale  \blt %m  Month  (01-12).
\bsp \blt %U  Week of the year (00-53) first Sunday is day 1 of week 1.
\bsp \blt %w  Weekday as number (0-6, Sunday is 0).
\bsp \blt %W  Week of the year (00-53) first Monday is day 1 of week 1.
\blt Convert integers (UNIX time) to POSIXct with the following:
\bsp class(anInt) <- Q "POSIXct"
\eSecBox

\sSecBox{Basic Stats}
\blt max/min         Min/Max of vector/list/factor
\blt mean            Can trim
\blt weighted.mean   Can't trim, but has weights
\blt median          50% quantile
\blt fivenum         0%, 25%, 50%, 70%, 100% quantiles
\blt quantile        more flexible than fivenum
\blt summary         min, 1st Qu, Median, Mean, 3rd Qu, Max
\blt sum/prod        Arithmetic sum/product
\blt var/sd          Variance/Standard deviation
\blt cov/cor/cov.wt  Covariance/Correlation/Weighted covariance
\blt cumsum/cumprod  Cumulative sums/products
\blt cummax/cummin   Cumulative max/min
\blt mad             median absolute deviation
\blt IQR             interquartile range
\eSecBox

\sSecBox{Classical Tests}
\textsc{NOTE: See} library(help=ctest) \textsc{for a complete list}
\blt ansari.test        \blt bartlett.test     \blt binom.test              
\blt chisq.test         \blt cor.test          \blt fisher.test             
\blt fligner.test       \blt friedman.test     \blt kruskal.test            
\blt ks.test            \blt mantelhaen.test   \blt mcnemar.test            
\blt mood.test          \blt oneway.test       \blt pairwise.prop.test      
\blt pairwise.t.test    \blt pairwise.table    \blt pairwise.wilcox.test    
\blt power.anova.test   \blt power.prop.test   \blt power.t.test            
\blt print.power.htest  \blt prop.test         \blt prop.trend.test         
\blt quade.test         \blt shapiro.test      \blt t.test                  
\blt var.test           \blt wilcox.test             
\eSecBox

\sSecBox{Data Smoothing}
\blt lowess          Cleveland lowess smoothing
\blt runmed          Moving median
\blt smooth          Tukey's smoothers
\blt smooth.spline   Fits a cubic smoothing spline to the supplied data.
\blt lowess          Cleveland's LOWESS smoother
\blt loess           Formula based version of lowess
\blt supsmu          Friedman's SuperSmoother
\blt convolve        General convolution
\bsp \bsp  Ex: convolve(data, rep(1,5), type='filter') \dfa 5pt moving average
\eSecBox

\sSecBox{Regression}
\blt Compute Regression Curves
\bsp \blt line       ROBUST regression line (EDA style)
\bsp \blt lm         Linear regression
\bsp \bsp Ex: lm(y~x, data=data.frame(x=1:10, y=2*(1:10)+3+rnorm(10)/5))
\bsp \blt nls        Nonlinear Least Squares
\bsp \bsp Ex: nls(y~a*x^2+b, data=data.frame(x=1:10, y=2*(1:10)^2+3+rnorm(10)/5), 
\bsp \bsp      start=list(a=10, b=10), trace=TRUE)
\blt Fitting objects
\bsp \blt summary    Summary of the fit (very useful)
\bsp \blt resid      residuals from a line object
\bsp \blt fitted     fitted points from a line object
\bsp \blt coef       fitted coefficients
\bsp \blt deviance   residual sum of squares
\bsp \blt anova      sequential analysis of variance
\bsp \blt predict    predict new values
\bsp \blt plot       A sequence of diagnostic plots
\eSecBox

\sSecBox{Sub Samples}
\blt sample          Sample n times from x without replacement
\bsp \blt replace    sample with replacement
\bsp \blt prob=vec   A vector of probabilities
\eSecBox

\sSecBox{Probability Distributions}
\blt Using Distributions
\bsp\blt d<dist> is density    \blt p<dist> is distribution
\bsp\blt r<dist> random number \blt q<dist> is the quantile
\blt Available Distributions
\bsp \bsp beta               beta        shape1, shape2
\bsp \bsp binomial           binom       size, prob
\bsp \bsp Cauchy             cauchy      location, scale
\bsp \bsp Chi-squared        chisq       df
\bsp \bsp exponential        f           rate
\bsp \bsp gamma              gamma       shape, rate
\bsp \bsp geometric          geom        prob
\bsp \bsp hypergeometric     hyper       m, n, k
\bsp \bsp log-normal         lnorm       meanlog, sdlong
\bsp \bsp logistic           logis       location, scale
\bsp \bsp negative binomial  nbinom      size, prob
\bsp \bsp normal             norm        mean, sd
\bsp \bsp Poisson            pois        lambda
\bsp \bsp T                  t           df
\bsp \bsp uniform            unif        min, max
\bsp \bsp Weibull            weibull     shape, scale
\bsp \bsp Wilcoxon           wilcox      m, n
\eSecBox

\sSecBox{I/O}
\blt read.table/read.csv  Read in a table/CSV file into a data.frame
\bsp\bsp\bsp\blt header             Header line (Boolean)
\bsp\bsp\bsp\blt sep                Separator (string)
\bsp\bsp\bsp\blt row.names          Vector of row names (strings)
\bsp\bsp\bsp\blt col.names          Vector of col names (strings)
\bsp\bsp\bsp\blt colClasses         Vector of col types (strings)
\bsp\bsp\bsp\blt nrows              Number of rows (integer)
\bsp\bsp\bsp\blt skip               Number of lines to skip (integer)
\bsp\bsp\bsp\blt blank.lines.skip   Skip blank lines (Boolean)
\bsp\bsp\bsp\blt comment.char       Skip comments (# for read.table)
\blt write                Write vectors and arrays
\blt source               Read in R code and evaluate it
\blt scan                 Read in data in very flexible manner
\blt download.file        Download a file from the net
\blt sink                 Send output to a file
\eSecBox

\sSecBox{R Options (\texttt{options} command)}
\blt echo       controls whether input is echoed in non-interactive mode
\blt verbose    Report extra information on progress
\blt device     Default graphics device (generally x11)
\blt na.action  Default function to handle NAs
\blt width      controls the number of characters on a line.
\blt editor     sets the default text editor
\blt pager      Program used for displaying ASCII files
\blt browser    default HTML browser used by help.start()
\eSecBox

\sSecBox{High Level Plot Functions}
Lattace      Traditional  Description
barchart     barplot      Barchart
bwplot       boxplot      Box-and-Wisker 
densityplot  NA           Kernel Density
dotplot      dotchart     Dotplot
histogram    hist         Histograms
qqmath       qqnrom       Quantile-quantile vs. distribution
stripplot    stripchart   1d scatterplot
qq           qqplot       Quantile-quantile plot
xyplot       plot         Scatterplot
levelplot    image        level plots
contourplot  contour      Contour Plot
cloud        NA           3d Scatterplot
wireframe    persp        surface in 3d
splom        pairs        Scatterplot matrix
parallel     NA           Parallel coord plots
\eSecBox

\sSecBox{Traditional Graphics}
\blt Draw an object in the plot region
\bsp \blt abline, polygon, rect, text
\bsp \bsp Ex: abline(b, m)   \dfa Draw: y=m*x+b
\bsp \bsp Ex: abline(h=b)    \dfa Draw: y=b
\bsp \bsp Ex: abline(v=a)    \dfa Draw: x=a
\blt Draw several objects in the plot region
\bsp \blt segments, arrows, points
\blt Draw objects in the margin space
\bsp \blt axis, mtext
\bsp \bsp Ex: mtext("hello", side=2, line=1)
\eSecBox

%\sSecBox{Old Style Graphics Options}
%\blt col                 \dfa Color
%\blt mar
%\eSecBox

\sSecBox{Arithmetic Operators}
\blt + - *    What you expect
\blt ^        Exponent
\blt %%       Integer Remainder (mod)
\blt /        Floating point division
\blt %/%      Integer division
\blt %*%      Matrix multiplication
\eSecBox

\sSecBox{Strings}
\blt sub, gsub          Pattern substitueion
\bsp \bsp Ex: sub('1', 'a', '212121')  \dfa   "2a2121"
\bsp \bsp Ex: gsub('1', 'a', '212121') \dfa   "2a2a2a"
\bsp \bsp Ex: gsub('.', 'a', '212121') \dfa   "aaaaaa"
\blt substr             SUB-STRings
\bsp \bsp Ex:  substr('123456', 2, 3)  \dfa   "23"
\blt nchar              Chracter length
\bsp \bsp Ex:  nchar(c('1234', '123')) \dfa c(4,3)
\blt paste, strsplit    Split & join
\bsp \bsp Ex:  strsplit("a,b,cd,e;f", ',')    \dfa c("a","b","cd","e;f")
\bsp \bsp Ex:  strsplit("a,b,cd,e;f", '[,;]') \dfa c("a","b","cd","e","f")
\bsp \bsp Ex:  paste("a", "b", sep='-')       \dfa "a-b"
\blt tolower, toupper   Case conversion
\blt chartr             Like UNIX tr
\bsp \bsp Ex:  chartr('abc', 'ABC', 'aAbBcC') \dfa   "AABBCC"
\blt grep, grepl        Searching for patterns
\bsp \bsp Ex:  grep("a.", c("bac", "a", "aa"))  \dfa c(1, 3)
\bsp \bsp Ex:  grepl("a.", c("bac", "a", "aa")) \dfa c(T, F, T)
\eSecBox

\sSecBox{Graphics Devices}
\blt Vector Files: postscript, pdf, cairo_pdf, cairo_ps
\bsp \bsp Ex:  pdf(file='foo.pdf', width=11, height=8.5)       \dfa letter sized 
\blt Raster Files: png, jpeg, tiff
\bsp \bsp Ex:  png(filename='foo.png', width=1024, height=768) \dfa XVGA sized 
\blt Interactive:  X11, quartz
\bsp \bsp Ex:  X11(display='foo.bar.com:0.0')                  \dfa Default size
\blt Generic Commands
\bsp \blt dev.cur()                  Current device
\bsp \blt dev.off(which=dev.cur())   Close current device
\bsp \bsp                            Must close to write files
\eSecBox

\end{document}

% function

% sort, order, unique

% reshape, table

% filter for time series

% pmin/pmax

% plot parameters

% match, %in%

%% R> match(1, c(2,1,2,2,3))      \dfa 2
%% R> match(1, c(2,2,2,3))        \dfa NA
%% R> 1 %in% c(2,2,2,1,3)         \dfa T
%% R> c(1,2,4) %in% c(2,2,2,1,3)  \dfa c(T, T, F)




% if, ifthen, while, for

% %in%, %*%, mod, 


% opeartors


