R
2026-07-12
Lab 2
The Chapter 2 lab is a tour of the language itself – vectors, matrices, indexing, plotting, and loading a data set. What follows is that tour, split into the sections the book uses.
Basic Commands
Vectors are built with c() (concatenate), and both <- and = assign. Arithmetic is element-wise, so operands must share a length – reassigning x to length 3 lets it line up with y:
Chapter 1: Getting Started
mean(abs(rnorm(100))) # generate 100 N(0,1) variates, take abs, then mean
rnorm(10)