Re: [R] problem on pg32 of ISwR

From: Gavin Simpson <>
Date: Thu, 21 Feb 2008 16:43:52 +0000

On Thu, 2008-02-21 at 11:06 -0500, b.r. clark wrote:
> > hist.with.normal<-function(x,xlab=deparse(substitute(x)),...)+ (+
> h<-hist(x, plot=F, ...)+ s<-sd(x)Error: unexpected symbol
> in:"h<-hist(x, plot=F, ...)s">
> I am using ISwR to teach myself R. Above is what happens when I try to
> duplicate the example on page 32. What went wrong? Note: I am using
> shift-enter to advance to the next line.

Don't type the "+". This is R indicating the it is waiting for you to complete the entry, and it is showing you this by changing the prompt to a "+".

Type is exactly as you see it, (not the ">" or "+"), so when you get to the end of a line, hit the return key (don't use shift-return), then you'll see R change the prompt to a "+".

You also appear to not by typing the braces "{" "}"

So you would type this exactly:

hist.with.normal<-function(x,xlab=deparse(substitute(x)),...) {

h <- hist(x, plot=FALSE, ...)
s <- sd(x)
m <- mean(x)

ylim <- range(0, h$density, dnorm(0, sd = s)) hist(x, freq = FALSE, ylim = ylim, xlab = xlab) curve(dnorm(x, m, s), add = TRUE)

Then, for example use it like so:

dat <- rlnorm(100)

Does this make sense?


 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e]
 Gower Street, London          [w]
 UK. WC1E 6BT.                 [w]

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 21 Feb 2008 - 16:48:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Feb 2008 - 17:30:16 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive