[R] tapply & hist

Vittorio v.demartino2 at virgilio.it
Thu May 13 21:59:04 CEST 2004


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 


to no avail




More information about the R-help mailing list