[R] classes and functions for qqnorm and stem

Peter Ehlers ehlers at ucalgary.ca
Thu Apr 15 13:06:37 CEST 2010


On 2010-04-14 21:20, Uwe Dippel wrote:
> Referring to "Using R for Data Analysis and Graphics" by J H Maindonald,
> and available from the R site, I found the example on p.30 non-working:
>  > stem(qqnorm(possum$hdlngth))
> Error in stem(qqnorm(possum$hdlngth)) : 'x' must be numeric
> Since qqnorm(possum$hdlngth) plots, and
>  > class(possum$hdlngth)
> [1] "numeric"
> , the problem must be here:
>  > class(qqnorm(possum$hdlngth))
> [1] "list"
> Does 'stem' require numerical input? The help says so.
> But how to render it numeric?:
>  > class(as.numeric(qqnorm(possum$hdlngth)))
> Error: (list) object cannot be coerced to type 'double'
>
> Can someone please enlighten me about what goes wrong/has changed here?

This is a perfect time to learn about str().
If you check

  str(qqnorm(possum$hdlngth))

You will see that it is a list of two numeric vectors. But
stem() expects just one vector. The stem(....) call is an
error; it should be just stem(possum$hdlngth).

  -Peter Ehlers

>
> Uwe
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list