The function shortlist below is far from complete because R has more to offer, but it lists the functions discussed in this Beginner's Guide to R.

RStudio - General
  • setwd(dir=...)
  • getwd()
  • instal.packages()
  • library()
  • vignette()
  • rm()
  • read.table(file=…, header=…, sep=…, dec=…)
  • write.table(…, file=…, sep=…, quote=…, append=…, na=…)
  • with(…, expr=…)
  • pfd(file=…)
  • help()
Operators/Symbols
<- assign values on the right to the variable on the left
= same, as used for input arguments in functions
== is equal to
< less than
> greater than
<= less or equal to
>= greater than of equal to
()


use to specify arguments for functions or conditions for control structures
use as mathematical operator to prioritize code to run: 2+3*5 = 17, (2+3)*5 = 25
[]
use to specify indices of variables. In variables with two dimensions (matrix/data.frame) row and column indices are separated by a comma: [row_index, column_index]
{} use in control structures to specify the code run by the control structure
$ use to specify a variable (column) in a data frame by name

Control structures
if (condition == TRUE) {
#do this
} else {
#do that
}
for (i in vector) {
#do this for length(vector) times, with the value of vector[loop_iteration] stored in i
}
while (condition == TRUE){
#do this until condition == FALSE
}
function (argument) {
do something
return(result)
}
Creating variables
  • c()
  • paste(…, sep=…)
  • vector(mode=…, length=…)
  • rep(…, each=…) OR rep(..., times=...)
  • seq(from=..., to=..., by=...)
  • factor(…, levels=…, labels=…)
  • array(…, dim=…)
  • matrix(…, nrow=…, ncol=…, byrow=….)
  • list()
  • data.frame()
  • rnorm()
  • runif()
  • as.character()
  • as.double()
  • as.integer()
  • as.logical()
  • as.factor()
  • as.Date(…, format=…)
Data information
  • class()
  • typeof()
  • is.character()
  • is.double()
  • is.integer()
  • is.logical()
  • is.factor()
  • is.numeric()
  • length()
  • dim()
  • nrow()
  • ncol()
  • table()
  • head()
  • tail()
  • names()
  • str()
  • unique()
  • summary()
Data manipulation
  • cbind()
  • rbind()
  • order(…, decreasing=…)
  • merge(x=…, y=…, by=…, all=…)
  • rowSums()
  • colSums()
  • sample()
Calculations
  • sum(…, na.rm=…)
  • mean(…, na.rm=…)
  • max(…, na.rm=…)
  • min(…, na.rm=…)
  • median(…, na.rm=…)
  • var(…, na.rm=…)
  • sd(…, na.rm=…)
  • sqrt()
  • log()
  • exp()
  • abs()
  • round()
Plotting
  • par(las=…, bg=…, mar=…, oma=…, mfrow=…, mfcol=…, add=…, cex=…)
  • plot.new()
  • plot.window(xlim=…, ylim=…)
  • windows(width=…, height=…) OR quartz(width=…, height=…)
  • plot(x=…, y=…, type=…, pch=…., lty=…, lwd=…, col=…, xlab=…, ylab=…, main=…)
  • barplot()
  • hist()
  • boxplot(y~x, data=…)
  • points()
  • lines()
  • abline()
  • segments()
  • arrows()
  • rect()
  • polygon()
  • text()
  • colors()
  • title()
  • mtext()
  • axis()
  • box()
  • dev.off()
  • graphics.off()
Linear Algebra
  • %*%
  • t()
  • diag()
Unlock full access  unlock