Appendices
Syntax cheat sheet, essential functions by category, operator reference, R version highlights, learning resources and suggested study plan (12 weeks).
Appendices
50.1 Syntax cheat sheet 50.2 Essential functions by category
c, seq, rep, vector, list, matrix, array, data.frame, tibble, factor
str, summary, head, tail, class, typeof, length, dim, names, nrow, ncol, glimpse
sum, mean, median, sd, var, min, max, range, round, abs, sqrt, exp, log, cumsum
which, any, all, ifelse, %in%, match, unique, duplicated, union, intersect, setdiff
sort, order, rank, rev, arrange paste, paste0, sprintf, nchar, substr, strsplit, gsub, grepl, toupper, trimws, str_*
apply, lapply, sapply, vapply, mapply, tapply, Map, Reduce, Filter, map_*
read.csv, write.csv, read_csv, readRDS, saveRDS, readLines, writeLines, fread, read_excel
t.test, chisq.test, cor, cor.test, lm, glm, aov, anova, predict, quantile, table
set.seed, sample, runif, rnorm, rbinom, rpois, replicate
ls, rm, exists, get, assign, environment, new.env, sys.call, match.arg
stop, warning, message, tryCatch, try, withCallingHandlers, on.exit, stopifnot
Sys.time, Sys.Date, Sys.getenv, system.time, invisible, identical, all.equal, do.call 50.3 Operator reference ! & | && || xor() matrix product, outer product list element, S4 slot anonymous function shorthand 50.4 R version highlights long vectors (> 2³¹ elements)
ALTREP, byte-compiled packages by default stringsAsFactors = FALSE default, raw strings r"(...)", new color palettes native pipe |>, \(x) lambda
_ pipe placeholder, UTF-8 on Windows, if errors on length > 1 conditions
&&/|| error on length > 1, _ extraction in pipes %||% in base, Tailcall() (experimental), sort_by()
grepv(), penguins dataset in base datasets, faster package installs 50.5 Learning resources Free books (online):
*R for Data Science* (2nd ed.) — Wickham, Çetinkaya-Rundel, Grolemund *Advanced R* (2nd ed.) — Hadley Wickham
*R Packages* (2nd ed.) — Wickham & Bryan *Hands-On Programming with R* — Garrett Grolemund
*ggplot2: Elegant Graphics for Data Analysis* (3rd ed.) — Wickham, Navarro, Pedersen *Tidy Modeling with R* — Kuhn & Silge
*Forecasting: Principles and Practice* (3rd ed.) — Hyndman & Athanasopoulos *Text Mining with R* — Silge & Robinson *Mastering Shiny* — Hadley Wickham
*Geocomputation with R* — Lovelace, Nowosad, Muenchow *An Introduction to Statistical Learning (ISLR2)* — James, Witten, Hastie, Tibshirani
*Statistical Rethinking* — Richard McElreath (book + lectures)
*Efficient R Programming* — Gillespie & Lovelace *Quarto documentation* — quarto.org
Interactive: swirl (learn R inside R), Posit Recipes/Primers, Exercism R track, DataCamp, Coursera (Johns Hopkins Data Science specialization)
Community: TidyTuesday, R-Ladies, R Weekly newsletter, R-bloggers, Posit Community, #rstats on Mastodon/Bluesky, useR! and posit::conf conferences, Stack Overflow [r] tag 50.6 Suggested study plan (12 weeks)
Install, console, help, packages, types, operators Vectors, NA, control flow, functions — Part I exercises
Matrices, lists, factors, data frames, apply family Strings, regex, dates, data import/export — Project 1 dplyr, tidyr, purrr
Base graphics, ggplot2, environments, conditions — Part II exercises, Project 2
EDA, probability & simulation, hypothesis testing Regression, GLMs, mixed models, multivariate, Bayesian — Project 3 tidymodels machine learning, time series — Project 4
OOP (S3/S4/R6/S7), metaprogramming, performance data.table, Rcpp, parallelism, big data — Project 7
Quarto, Shiny, APIs, text, spatial, packages, workflow — Project 5 or 6 🎓 Final Words
You've traveled from x <- 5 to tidy evaluation, Rcpp, Arrow, tidymodels, Shiny, and package development. R's strength is its community and its focus on data — so practice on real datasets (join TidyTuesday!), read *R for Data Science* and *Advanced R*, share your work with Quarto, and build the capstone projects. Happy analyzing! 📊
# Assignment & types
x <- 5; y <- "text"; z <- TRUE; v <- c(1, 2, 3); typeof(x); class(v); str(v)
# Indexing
v[1]; v[-1]; v[v > 1]; lst[["a"]]; lst$a; df[1, ]; df[, "col"]; df$col; m[i, j]
# Control flow
if (cond) { ... } else { ... }
for (i in seq_along(v)) { ... }
while (cond) { ... }
switch(type, a = 1, b = 2)
# Functions
f <- function(x, y = 2, ...) { x + y }
\(x) x^2
do.call(f, list(1, 2)); Reduce(`+`, 1:5); Map(`+`, 1:3, 4:6)
# Data frames & tidyverse
df |> filter(a > 1) |> select(a, b) |> mutate(c = a * b) |> group_by(g) |> summarise(m = mean(c)) |> arrange(desc(m))
pivot_longer(df, -id); left_join(x, y, by = "id"); map_dbl(lst, mean)
# Plotting
ggplot(df, aes(x, y, color = g)) + geom_point() + facet_wrap(~ g) + theme_minimal()
# Statistics & models
mean(x, na.rm = TRUE); sd(x); t.test(y ~ g, df); lm(y ~ x, df); glm(y ~ x, family = binomial, df)
# Errors
tryCatch(expr, error = function(e) ..., finally = ...)
stop("msg"); warning("msg"); message("msg")
# Packages & help
install.packages("pkg"); library(pkg); pkg::fun(); ?fun; vignette("pkg")