[R] Histogram

Mulholland, Tom Tom.Mulholland at dpi.wa.gov.au
Thu Apr 21 03:56:45 CEST 2005


Of course Andy meant hist.factor(f)

In particular you should note that Andy uses the table function to "transform ... the data from characters to numbers"

Tom

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Liaw, Andy
> Sent: Thursday, 21 April 2005 12:14 AM
> To: 'ferri.leberl at gmx.at'; r-help at stat.math.ethz.ch
> Subject: RE: [R] Histogram
> 
> 
> > From: Mag. Ferri Leberl
> > 
> > Dear everybody!
> > I am analysing data from an enquette. The answers are either 
> > A or B. How can I 
> > draw a histogram without transforming the data from 
> > characters to numbers? If 
> > the data are saved in a list M, hist(M[,1]) returns:
> > 
> > Error in hist.default(M[, 1]) : `x' must be numeric
> > Execution halted
> 
> You can try:
> 
> > hist.factor <- function(x, ...) barplot(table(x), ...)
> > f <- factor(sample(c("A", "B"), 50, replace=TRUE))
> > hist(f)
> 
> HTH,
> Andy
>  
> > Thank you in advance!
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list