[R] problem on pg32 of ISwR
Gavin Simpson
gavin.simpson at ucl.ac.uk
Thu Feb 21 17:43:52 CET 2008
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)
hist.with.normal(dat)
Does this make sense?
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list