[R] tapply & hist
Gabor Grothendieck
ggrothendieck at myway.com
Thu May 13 22:46:40 CEST 2004
As another respondent already mentioned, Lattice is probably the way to
go on this one but if you do want to use tapply try this:
names(Pot) <- SGruppo
dummy <- tapply(Pot,SGruppo,function(x)hist(x,main=names(x)[1],xlab=NULL))
Vittorio <v.demartino2 <at> virgilio.it> writes:
:
: I'm learning how to use tapply.
: Now I'm having a go at the following code in which dati contains almost 600
: lines, Pot - numeric - are the capacities of power plants and SGruppo - text
: - the corresponding six technologies
("CCC", "CIC","TGC", "CSC","CPC", "TE").
: .....................................................
:
: dati=sqlQuery(canale,"select Id,SGruppo,Classe, NGruppo,ProdNetta,Pot from
: SintesiQuery")
: attach(dati)
: # Grouping by technology
: tapply(Pot,SGruppo,sum)
: ...................................
: # Histograms by technology
: par(mfrow=c(2,3))
: tapply(Pot,SGruppo,hist)
: detach(dati)
:
: It all works great but tapply(Pot,SGruppo,hist) produces 6 histograms with
: the titles and the xlab labels in a generic form, something like integer[1],
: integer[2], ....... while I'd like to have each graph indicating the
: mentioned technologies.
: I've been trying issuing
: tech=c("CCC", "CIC","TGC", "CSC","CPC", "TE")
: tapply(Pot,SGruppo,hist, main=tech)
:
: but R prints in each histogram the six values in the title without cycling
: among them.
:
: How can I obtain what I want?
:
: Ciao
: Vittorio
More information about the R-help
mailing list