Errata

R Cookbook

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

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

Version Location Description Submitted by Date submitted
Printed Page 29
Data frame output

The output of the data frame has seven columns. The last column was created in the code and called "pos". However the header for that column is missing in the output sample. So "pos" should appear directly above "FALSE" in the table.

Doug Mitarotonda  Aug 14, 2013 
Printed Page 31
last command on page

At the bottom of page 31, you have the command print(dframe), but you haven't shown how to load dframe.

David Arnold  Jan 01, 2012 
PDF Page 31
Last paragraph

This was correct syntax in an old version of R but the following is not true in current versions of R:

"A beautiful aspect of mean and sd is that they are smart about data frames."

To get sum of rows or columns you must use rowsum or colsum.

I wish there would be a revised edition to correct such issues. I'll bet there are more.

Daniel Johansson  Nov 09, 2017 
Printed Page 48
paragraph "Passing multiple arguments..."

Original phrase:
"Other arguments, such as max and min, take multiple arguments..."
Correct phrase:
"Other functions, such as max and min, take multiple arguments..."

Jose Osorio Azevedo Neto  Oct 05, 2012 
PDF Page 72
Solution

Solution (i.e., > scores <- edit(score) # Invoke editor, overwrite with edited data) should read edit(scores) rather than "edit(score)" in order to produce a result in R.

Chris Rucker  Apr 14, 2015 
Printed Page 73
Last row of numbers

The print(pnorm(-3:3), digits=3) function asks for 3 digits. The result of such a function showed by the book is the following:

[1] 0.00135 0.02275 0.15866 0.50000 0.84134 0.97725 0.9986

The last paragraph outlines "Notice that print formats the vector elements consistently: finding the number of digits necessary to format the smallest number and then formatting all numbers to have the same width (though not necessarily the same number of digits)".

Collectively, I found confusing the explanation because there is a typo error in the last figure (0.9986 must be 0.99865).

Fer Estévez-López  May 07, 2019 
Printed, PDF Page 129

wrong : third columns
correct : fourth columns

wrong : > suburbs[c(1,3)]
correct : > suburbs[c(1,4)]

Shinya OHASHI  Nov 10, 2011 
Printed Page 147
Code line for f

You have:

f <- factor(c("A","C","C","B","C"))

But in the diagram that follows, you write the factor as:

A
C
A
B
C

So, you need to make this change:


f <- factor(c("A","C","A","B","C"))

David Arnold  Jul 21, 2012 
PDF Page 170
5th paragraph

"See the help page for the stftime function" should be " See the help page for the strftime function". strftime, not stftime

Michael Aeschbach  Jan 17, 2012 
Printed Page 174
yday

yday does not give the day of the year but rather the number of days since Jan 1

> testdate<- as.Date("2011-1-31")
> as.POSIXlt(testdate)$yday
[1] 30

thus to get the day of the year the command should be

as.POSIXlt(testdate)$yday + 1

alternatively, if one uses strftime, one gets the correct answer

> as.numeric(strftime(testdate, "%j"))
[1] 31

Anonymous  Aug 18, 2011 
Printed Page 215
2nd sample code line

'spearman' should not be capitalized in method. Same problem on p 216, 4th paragraph

Anonymous  Nov 21, 2011 
Printed, PDF Page 254
Recipe 10.22

The plot() and abline() method used to draw a straight line through the data points on the Q-Q plot for the exponential distribution, does not give a good fit, see Fig 10-21.

There is no explanation of why abline(0,1) should give a good fit for non-normal distributions, and the statistical explanation for using these parameters is not obvious (to me). a=0, b=1 should apply to a standard normal distribution?

A better method is to use qqplot in combination with qqline, see the R help for qqline. For the exponential distribution example the R code is:
y <- rexp(500,rate=1/10)
qqplot(qexp(ppoints(500),rate=1/10), y,
+ main='Q-Q Plot for Exponential',
+ xlab='Theoretical Quantiles',ylab='Sample Quantiles')
qqline(y, distribution = function(p) qexp(p, rate=1/10),
+ prob=c(0.25,0.75), col=2)

As you can see , the qqline give a much better fit to the data than Fig 10-21.

Peter Arrowsmith  Sep 24, 2013 
Printed Page 294
1st paragraph

The function outlier.test() in package car is now deprecated and raises an error.
It should be replaced by function outlierTest().

Cedric Duprez  Feb 06, 2013 
Printed, PDF Page 302
The Discussion paragraph

"The data covers the period 1950 though 2009" -> " ... 1950 through 2009"

Qiusheng Wu  Mar 11, 2016 
Printed Page 306
the paragraph after the table

The first line in the table, for example, compares the Tue group and the Mon group, not "Wed" group.

Qiusheng Wu  Mar 11, 2016 
Printed Page 330
1st paragraph

The second code example mentions "suppressuWarnings()" function instead of "suppressWarnings()".
The middle "u" is a typo.

Cedric Duprez  Jun 09, 2011 
Printed Page 330
at the Top

Page 330, at the top, incorrectly lists the suppressMessages() function as
suppressMessage(). You left out the "s".

Anonymous  Mar 04, 2014 
Printed Page 404
I entries, second line

This is in the index. The line says:
if statements, 48
But there is no mention about if statements in this page. Also, in page 413 we have:
while statements, 48
Again we have no mention of while statements in that page.
Furthermore, flow control statements were completely forgotten in this book. They surely deserved at least a mention.

Jose Osorio Azevedo Neto  Oct 05, 2012 
Other Digital Version 1089
Two lines under 'Solution'

The test reads:

Use the prop.test function. Suppose the sample
size is n and the sample contains
x successes:

> prop.test(n, x)

It should read as:

> prop.test(x, n)

Joshua Sumali  Apr 20, 2012