1  Preface

Throughout this book you will see boxes with R code followed by its output, if any. The code (or input) is decorated with a teal border on the left to separate it from its output, like in the following example:

x <- rnorm(200)
x[1:20]
 [1] -1.13342287  1.11353337 -0.03702872 -1.48267906 -2.05752407 -0.62613526
 [7] -0.91301161 -0.36634625  1.11780985  0.44857895 -1.05760229  0.56941699
[13]  1.25505845  0.75266861  0.34404530 -0.60977115  1.61328837  0.98310636
[19] -1.25425408 -1.49492550

Notice that R adds numbers in brackets in the beginning of each row. This happens when R prints the contents of a vector. The number is the integer index of the first element in that row. Therefore, the first one is always [1] and the number of the subsequent rows depends on how many elements fit in each line. If the output is a single element, it will still have [1] in front of it.

Also notice that if we enclose the assignment operation of a variable in parentheses, this prints the resulting value of the variable. Therefore, this:

(y <- 4)
[1] 4

is equivalent to:

y <- 4
y
[1] 4

Currently, this site uses Fira Code to display source code, which supports multiple character ligatures that make code prettier / easier to read.

Ligated versions of some common character combinations as they should appear in this site

Note that if you mouse over the input code box, a clickable “Copy to clipboard” appears on the top right of the box allowing you to copy paste into an R session or file.

This book was created using Quarto, ported from the previous version which used bookdown.