Appendix B

R

B.1 Vectors

Command

What it does

c(1,1,0,2.7,3.1)

creates the vector (1,1, 0, 2.7, 3.1)

1:100

creates the vector (1, 2,... , 100)

(1:100)^3

creates the vector (13, 23,. .. , 1003)

rep(0,50)

creates the vector (0, 0,... , 0) of length 50

seq(0,99,3)

creates the vector (0, 3, 6, 9,... , 99)

v[5]

5th entry of vector v (index starts at 1)

v[-5]

all but the 5th entry of v

v[c(3,1,4)]

3rd, 1st, 4th entries of vector v

v[v>2]

entries of v that exceed 2

which(v>2)

indices of v such that entry exceeds 2

which(v==7)

indices of v such that entry equals 7

min(v)

minimum of v

max(v)

maximum of v

which.max(v)

indices where max(v) is achieved

sum(v)

sum of the entries in v

cumsum(v)

cumulative sums of the ...

Get Introduction to Probability now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.