Section 13 A List of Useful R Functions

Hadley Wickham compiled a list of most useful functions of the base, stats, and utils packages. You can check the list in the website of his book (http://adv-r.had.co.nz/Vocabulary.html).

We have covered most of these functions in this course. Here I have compiled a shorter version based on the base, stats, and utils packages. As an R programmer, try to understand these functions. Check the help file for further details if you are not sure.

13.1 Common functions

# The first functions to learn
?
str

# Important operators and assignment
%in%, match
=, <-
$, [, [[, head, tail, subset
with
assign, get

# Comparison 
all.equal, identical
!=, ==, >, >=, <, <=
is.na, complete.cases
is.finite

# Basic math
*, +, -, /, ^, %%, %/%
abs, sign
acos, asin, atan, atan2
sin, cos, tan
ceiling, floor, round, trunc, signif
exp, log, log10, log2, sqrt

max, min, prod, sum
cummax, cummin, cumprod, cumsum, diff
range
mean, median, cor, sd, var


# Logical & sets 
&, |, !, xor
all, any
intersect, union, setdiff, setequal
which

# Vectors and matrices
c, matrix

# automatic coercion rules character > numeric > logical
length, dim, ncol, nrow
cbind, rbind
names, colnames, rownames
t
diag
sweep
as.matrix, data.matrix


# Making vectors 
c
rep, rep_len
seq, seq_len, seq_along
rev
sample
choose, factorial, combn
(is/as).(character/numeric/logical/...)


# Control flow 
if, &&, || (short circuiting)
for, while
next, break
switch
ifelse

# Apply & friends
lapply, sapply, vapply
apply
tapply
replicate

13.2 Common data structure

# vector, list, dataframe
vector
matrix
array
data.frame
list
unlist
as.data.frame
split
expand.grid

# Factors 
factor, levels, nlevels
reorder, relevel
cut, findInterval
interaction
options(stringsAsFactors = FALSE)

# Ordering and tabulating 
duplicated, unique
merge
order, rank, quantile
sort
table, ftable
split

13.3 Working with R

# Workspace 
ls, exists, rm
getwd, setwd
q
source
install.packages, library, require

# Help
help, ?
help.search
apropos
RSiteSearch
citation
demo
example
vignette

# Debugging
traceback
browser
recover

# Output
print, cat
message, warning


# Reading and writing data
data
count.fields
read.table, read.csv, 
write.table, write.csv

load, save, save.image