R Command Index

Where to review the R patterns used in the workbook

A running reference for R commands and the chapter where each one is introduced.

Use this page when you recognize a command but need a reminder about what it does. The index records where each command is first explained. Later chapters may reuse a command without teaching it again.

Start Here Commands

Command or pattern What it does First explained
<- Stores a result in a named object. Run Your First Script
# Adds a comment for readers. R ignores the rest of that line. Run Your First Script
|> Passes the result of one step into the next step. Run Your First Script
nrow() Counts observations in a data frame. Run Your First Script
ncol() Counts variables in a data frame. Run Your First Script
names() Lists variable names in a data frame. Run Your First Script
count() Counts how often values or categories occur. Run Your First Script

How To Read The Examples

R functions use parentheses:

function_name(object, option = value)

Pipes organize a sequence from left to right:

data_object |>
  first_step() |>
  next_step()

Assignment saves a result so it can be inspected or reused:

result_name <- data_object |>
  analysis_step()

Chapter Commands

Chapters 1 And 2: Inspect, Label, Tabulate, And Graph

Command or pattern What it does First explained
source() Runs code saved in another script. Chapter 1
dim() Reports observations and variables together. Chapter 1
factor() Gives category codes readable labels and an order. Chapter 1
$ Selects one variable inside a data frame. Chapter 1
levels() Shows the labels and order of a factor. Chapter 1
mutate() Changes or creates variables. Chapter 1
ggplot() + aes() Starts a graph and maps variables to visual positions. Chapter 1
geom_col() Creates bars from values already calculated in a table. Chapter 1
labs() Adds readable graph labels. Chapter 1
class() Shows how R represents an object or variable. Chapter 2
cumsum() Creates a running total. Chapter 2
drop_na() Omits observations missing specified values from an analysis. Chapter 2
geom_histogram() Groups quantitative scores into intervals and graphs their frequencies. Chapter 2
coord_flip() Turns a graph so long category labels are easier to read. Chapter 2

Chapters 3-5: Describe Distributions

Command or pattern What it does First explained
filter() Keeps observations that meet a condition. Chapters 3 and 4
group_by() Requests later calculations separately for each group. Chapters 3 and 4
summarise() Reduces observations to named summary values. Chapters 3 and 4
n() Counts observations inside a summary. Chapters 3 and 4
mean(), median(), sd() Calculate center and variability. Chapters 3 and 4
min(), max() Find the observed endpoints. Chapters 3 and 4
sum(), is.na() Count missing values when they matter to a summary. Chapters 3 and 4
facet_wrap() Repeats a graph in separate group panels. Chapters 3 and 4
statistical_mode() Returns the most common observed value. This helper is supplied by the setup file. Chapters 3 and 4
head() Displays the first observations or values in an object. Chapter 5
quantile() Calculates quartiles or other percentiles. Chapter 5
IQR() Calculates the interquartile range. Chapter 5
geom_boxplot() Creates a boxplot. Chapter 5
independent_cohens_d() Calculates Cohen’s d for two independent groups. This helper is supplied by the setup file. Chapter 5

Chapters 6, 9, And 10: Correlation And t Tests

Command or pattern What it does First explained
select() Keeps specified variables. Chapter 6
cor() Calculates Pearson correlation coefficients. Chapter 6
outcome ~ predictor Identifies the outcome and predictor in an R model formula. Chapter 6
lm() Fits a linear model. Chapter 6
coefficients() Shows a model’s intercept and slope. Chapter 6
geom_point(), geom_smooth() Add observed score pairs and a fitted line. Chapter 6
t.test() Conducts a t test. Chapter 9
sample_skewness() Calculates sample skewness. This helper is supplied by the setup file. Chapter 9
cohens_d() Divides a mean difference by a standard deviation. This helper is supplied by the setup file. Chapter 9
mu = Supplies the comparison value for a one-sample test. Chapter 9
alternative = "two.sided" Requests a non-directional test. Chapter 9
$conf.int Retrieves the confidence interval stored in a test object. Chapter 9
pull() Takes one variable from a data frame for use by a function. Chapter 10
shapiro.test() Checks whether scores differ significantly from a normal distribution. Chapter 10
var.test() Conducts an F test comparing two group variances. Chapter 10
var.equal = TRUE Requests Student’s independent-samples t test. Chapter 10
paired = TRUE Identifies two related sets of scores. Chapter 10

Chapters 11-14: ANOVA And Chi-Square

Command or pattern What it does First explained
aov() Fits an analysis-of-variance model. Chapter 11
summary(model) Prints the ANOVA table stored in a model object. Chapter 11
residuals() Retrieves observed-minus-predicted differences from a model. Chapter 11
bartlett.test() Checks whether three or more group variances differ. Chapter 11
qt() Supplies the critical t value used to calculate a confidence interval. Chapter 11
anova_eta_squared() Calculates eta squared for a one-way ANOVA. This helper is supplied by the setup file. Chapter 11
TukeyHSD() Conducts adjusted pairwise comparisons. Chapter 11
tukey_cohens_d() Calculates Cohen’s d for Tukey comparisons. This helper is supplied by the setup file. Chapter 11
geom_errorbar() Adds confidence intervals to a graph. Chapter 11
row_number() Creates a participant label from observation order. Chapter 12
pivot_longer() Reshapes repeated scores from wide to long format. Chapter 12
repeated_eta_squared() Calculates partial eta squared for the repeated condition. This helper is supplied by the setup file. Chapter 12
repeated_pairwise_tests() Compares each pair of repeated scores and reports mean differences, Tukey-adjusted p values, and Cohen’s d. This helper is supplied by the setup file. Chapter 12
interaction() Combines grouping variables for an assumption check. Chapter 13
predictor_1 * predictor_2 Requests two main effects and their interaction. Chapter 13
two_way_anova_table() Reports two-way tests with partial eta squared. This helper is supplied by the setup file. Chapter 13
geom_line() Connects means in an interaction plot. Chapter 13
table() Creates observed frequency or contingency tables. Chapter 14
chisq.test() Conducts chi-square tests. Chapter 14
test_object$expected Retrieves expected counts. Chapter 14
cramers_v() Calculates Cramer’s V. This helper is supplied by the setup file. Chapter 14
prop.table() Converts counts to proportions. Chapter 14
p = c(...) Supplies the expected proportions for a goodness-of-fit test. Chapter 14

Chapter 15: Nonparametric Statistics

Command or pattern What it does First explained
wilcox.test(outcome ~ group) Conducts a Mann-Whitney U test for two independent groups. Chapter 15
wilcox.test(x, y, paired = TRUE) Conducts a Wilcoxon signed-rank test for paired scores. Chapter 15
rank_biserial_independent() Calculates rank-biserial correlation for two independent groups. This helper is supplied by the setup file. Chapter 15
rank_biserial_paired() Calculates rank-biserial correlation for paired scores. This helper is supplied by the setup file. Chapter 15
kruskal.test() Conducts a Kruskal-Wallis test. Chapter 15
kruskal_epsilon_squared() Calculates epsilon squared for a Kruskal-Wallis test. This helper is supplied by the setup file. Chapter 15
dscfAllPairsTest() Conducts DSCF post hoc comparisons after a significant Kruskal-Wallis test. Chapter 15
cor.test(..., method = "spearman") Conducts a Spearman rank correlation. Chapter 15