Errata

Learning R

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed, PDF, ePub, Mobi, , Other Digital Version
Page xii
4th paragraph

I stated that "Garrett Grolemund’s Data Analysis with R picks up where
this book leaves off".

It seems that after I spoke to Garrett, he took his book in a different direction. It is now called "Hands-on Programming with R", and it's much more of a beginners book. It is excellently written and definitely worth reading, but the content is easier than in Learning R. Buy it here:
http://shop.oreilly.com/product/0636920028574.do

For more advanced R coding, try Hadley Wickham's "Advanced R". http://adv-r.had.co.nz/

Note from the Author or Editor:
In the second paragraph, change

"If you want a really introductory text on how to program, then Python for Kids by Jason R. Briggs is as good a place to start as any!"

to

"Garrett Grolemund's Hands-on Programming with R" provides an excellent, slow-paced introduction to using R that assumes no programming experience. Alternatively, if you want a really introductory text on how to program, then Python for Kids by Jason R. Briggs is as good a place to start as any!"

Then in paragraphs four, change

"Garrett Grolemund’s _Data Analysis with R_ picks up where this book leaves off, covering data analysis workflow in more detail."

to

"Hadley Wickham's _Advanced R_ and _R Packages_ pick up where this book leaves off, covering technical topics in more detail."

Richie Cotton  Aug 26, 2014 
CH2
Chapter 2:Logical Vectors, 1st paragraph, second sentence

The book reads " This three-state system is sometimes call troolean logic..."

"call" should be "called"

Anonymous  Sep 03, 2015 
PDF
Page 28
1st paragraph under RStudio

www.rstudio.org should be www.rstudio.com

Note from the Author or Editor:
Yes, the URL has moved to https://www.rstudio.com

Nico Verwer  Aug 18, 2014 
PDF
Page 50
Preceding section heading: Row, Column, and Dimension Names

A line has been omitted. The output of "dim(recaman)" which should be "NULL" was left out of the example preceding that heading.

Note from the Author or Editor:
The variable in the examples on p50 is sometimes incorrectly named "x" rather than "recaman". The text should read"

recaman <- c(0, 1, 3, 6, 2, 7, 13, 20) #See http://oeis.org/A005132
nrow(recaman)
## NULL
NROW(recaman)
## [1] 8
ncol(recaman)
## NULL
NCOL(recaman)
## [1] 1
dim(recaman)
## NULL

Stewart Patch  Mar 15, 2014 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 50
top

The first liine of code on p50 defines a variable, 'recaman'. Subsequent lines refer to this as 'x', which menas that the code gives incorrect results.

The correct output should be:

recaman <- c(0, 1, 3, 6, 2, 7, 13, 20)
nrow(recaman)
## NULL
NROW(recaman)
## [1] 8
ncol(recaman)
## NULL
NCOL(recaman)
## [1] 1
dim(recaman)
## NULL

Richie Cotton  Jul 12, 2014 
PDF
Page 53
1st paragraph

The second sentence states that for multiplication the number of rows of the first matrix must be equal to the number of columns of the second matrix. However the form of multiplication discussed here is element-wise so that for both addition and multiplication the two matrices must have their corresponding dimensions equal.

The rule given for multiplcation in this paragraph is like, but backwards to, the rule for the inner product of matrices which requires the number of columns of the first matrix to be equal to the number of rows of the second matrix.

Note from the Author or Editor:
The erratum is correct that the text doesn't properly distinguish elementwise and matrix inner multiplication, and that the rule is backwards.

The text needs quite a lot of editing and rearranging to make sense. In particular, it's clearer if the bit on transposition needs moving after the bit on inner/outer multiplication. It should read:

When performing elementwise arithmetic on two arrays, you need to make sure that both arrays must be the same size (they are “conformable,” in linear algebra terminology). For ex
ample:

(a_differently_sized_matrix <- matrix(1:12, nrow = 2))
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 1 3 5 7 9 11
## [2,] 2 4 6 8 10 12
a_matrix + a_differently_sized_matrix
## Error in a_matrix + a_differently_sized_matrix : non-conformable arrays

For inner and outer matrix multiplication, we have the special operators %*% and %o%. In this case, conformable means that the number of columns in the first matrix must be the same as the number of rows in the second matrix. In each case, the dimension names are taken from the first input, if they exist:

<examples for inner and outer product here, unchanged>

<text and example for transposition function here, unchanged>

Stewart Patch  Mar 16, 2014 
PDF
Page 55
Exercise 4-2

The exercise is "Create a 21-by-21 matrix with the sequence 10 to 0 to 11 (i.e. 11, 10,..., 0, 1,... ,11)."

However the vector given as an example has 23 elements so it would generate a 23-by-23 matrix. Should the initial vector have been 10 to 0 to 10 (i.e. 10, 9,..., 0, 1.,..., 9, 10) as this would have 21 elements?

Note from the Author or Editor:
The text on p55 should be changed to:

"Create a 21-by-21 matrix with the sequence 10 down to 0 then back up to 10 on the diagonal."

Then the answer to Ex4-2 on p342 should be changed to:

diag(abs(seq.int(-10, 10)))

Stewart Patch  Mar 17, 2014 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 59
Code in middle of page

When creating the nested list, in the line

element_in_inner_list = pi ^ 1:4

there should be parentheses around 1:4. that is, the line should read

element_in_inner_list = pi ^ (1:4)

The corresponding output for that line should be

## [1] 3.141593 9.869604 31.006277 97.409091

Richie Cotton  Jul 13, 2014 
Printed
Page 60
1st paragraph, lines 2-3

I stated that "Variables can either be atomic or recursive, never both". I failed to mention that there is a (rather obscure) variable type called a name, which contains the name of a variable, that is neither atomic nor recursive.

a <- as.name("x")
is.atomic(a)
## FALSE
is.recursive(a)
## FALSE

Richie Cotton  Oct 15, 2013 
Printed
Page 123
Table at top

In first line of table in Exercise 8-1, the score value should be: 2, 3, 12. (Not 2,3,11).

Paul Junker  Jun 23, 2014 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 130
last line of code

The line

vapply(list(), length, numeric(1))

is technically correct, but since length returns an integer, it would have been better to write

vapply(list(), length, integer(1))

Richard Cotton  Apr 07, 2015 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 226
Last line of text

There is an accidental "+" symbol before the word "lattice".

Richie Cotton  Sep 10, 2014 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 281
7th paragraph

For data mining, I recommend Graham Williams "Data
Mining with Rattle and R" (and Max Kuhn's "Applied Predictive Modeling" on the previous page). These are both great books, but my new go-to introduction to data mining in R is Brett Lantz's "Machine Learning with R".

https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-r

Read Lantz's book first, then Kuhn's, then Williams'.

Note from the Author or Editor:
After the text about Rattle, add the sentence:

"Brett Lantz's _Machine Learning with R_ also provides an excellent introduction to data mining concepts in R."

Richie Cotton  Mar 20, 2015 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 303
Second numbered list

The list of object-oriented systems in add-on packages omits these two systems.

R6: A faster, lighter-weight alternative to reference classes.

mutatr: A now-defunct package for prototype-based OOP, similar to proto.

Richie Cotton  Oct 15, 2015 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 323
Before the summary

If this chapter was interesting to you and you want to read more, try "R Packages" by Hadley Wickham.

http://r-pkgs.had.co.nz

Note from the Author or Editor:
Add the text + reference

Richie Cotton  Mar 20, 2015 
Other Digital Version
716
Kindle edition loc: 716 (in chapter 2, paragraph before "Logical Vectors"

"Notice that NaN and NA are neither finite nor infinite, and NaN is missing but NA is a number:"

should read:
"Notice that NaN and NA are neither finite nor infinite, and NA is missing but NaN is a number:"

Note from the Author or Editor:
The sentence is wrong, but not in the way presented in the erratum. It should read

"Notice that NaN and NA are neither finite nor infinite, and NaN is missing but NA is not not-a-number[link to footnote]."

[footnote] Not being not-a-number is not the same as being a number!

Anonymous  Jan 17, 2014 
Printed, PDF, ePub, Mobi, , Other Digital Version
Page 8975
Question 2-3

Kindle Edition

Appendix C. Answers to Quizzes
Question 2-3
At least two of the following:
1. <-
2. + = (should be =)
3. + <<- (should be <<-)
4. assign

Note from the Author or Editor:
The "+ " is caused by bad formatting of the underlying AsciiDoc markup. The erratum is correct: responses 2 and 3 should be "=" and "<<-" respectively.

Anonymous  Jan 17, 2014