[R] Histogram for factors

Martin Maechler maechler at stat.math.ethz.ch
Sat Jan 13 10:31:16 CET 2001

>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:

    PD> Thomas Vogels <tov at ece.cmu.edu> writes:
    >> Hi,
    >> I keep running into this:
    R> hist (f)
    >> Error in hist.default(f) : `x' must be numeric
    >> To which of course something like (simplified but not beyond
    >> repair):
    R> hist.factor <- function (ff) {
    >> jj <- table (ff) jb <- barplot (jj, ylab="Frequency",
    >> xlab=deparse(substitute(ff))) axis (1, jb, names (jj)) }
    R> hist (f)
    >> is a possible solution.
    >> Why is a 'hist.factor' not part of the base distribution?  Is this
    >> kind of thing discouraged?  Usually not needed?  Am I missing sth
    >> else?

    PD> Well histograms are density estimates defined for continuous
    PD> variables. What you're drawing is a barplot. barplot.factor might
    PD> be a good idea, though.

already draws a barplot of a factor f (by the  plot.factor method).

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list