Mea Culpa I did copy and paste your code to make sure it was an error. I'll go and do it again before I reply.
It worked as you expected it to. So I located where I had done it and this is what I found > f <- factor(sample(c("A", "B"), 50, replace=TRUE)) > hist(f) Error in hist.default(f) : 'x' must be numeric Since I had more than one session open I had inadvertantly pasted the > hist.factor <- function(x, ...) barplot(table(x), ...) into another window. For some reason or other I have always had finger trouble with the "paste commands only" in the windows GUI, so I do it one line at a time or past into Tinn-R and select with the alt key. I guess its time for me to actually understand methods, because it's patently obvious I don't even though I was beginning to think I had a handle on them. Tom > -----Original Message----- > From: Liaw, Andy [mailto:[EMAIL PROTECTED] > Sent: Thursday, 21 April 2005 10:06 AM > To: Mulholland, Tom > Subject: RE: [R] Histogram > > > Have you tried it? hist.factor() as defined would be the > hist method for > the factor class, so hist(f) would work if f is a factor. > > Andy > > > From: Mulholland, Tom > > > > 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: [EMAIL PROTECTED] > > > [mailto:[EMAIL PROTECTED] Behalf Of Liaw, Andy > > > Sent: Thursday, 21 April 2005 12:14 AM > > > To: '[EMAIL PROTECTED]'; r-help@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@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 > > > > > > > > > > > > > -------------------------------------------------------------- > ---------------- > Notice: This e-mail message, together with any attachments, > contains information of Merck & Co., Inc. (One Merck Drive, > Whitehouse Station, New Jersey, USA 08889), and/or its > affiliates (which may be known outside the United States as > Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as > Banyu) that may be confidential, proprietary copyrighted > and/or legally privileged. It is intended solely for the use > of the individual or entity named on this message. If you > are not the intended recipient, and have received this > message in error, please notify us immediately by reply > e-mail and then delete it from your system. > -------------------------------------------------------------- > ---------------- > ______________________________________________ R-help@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