Hi, how can I tell 'summary' to print the name of the summarised variable? This is probably an awkward newbie question but I didn't find an answer in the Docus, the FAQ and maillist archive. I want a summary for about 250 variables and realise it the following way (I know, that I shouldn't use iterations that way in R; but at the moment it's the easiest way for me): for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} It works fine, but I don't know which summary corresponds to which variable, because the variable names are not printed. Can somebody give me a hint? TIA Regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: bier at wiz.uni-kassel.de Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13
Christoph Bier wrote:> Hi, > > how can I tell 'summary' to print the name of the summarised variable? > This is probably an awkward newbie question but I didn't find an answer > in the Docus, the FAQ and maillist archive. > I want a summary for about 250 variables and realise it the following > way (I know, that I shouldn't use iterations that way in R; but at the > moment it's the easiest way for me): > > for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))}Given fb.12.unt is a list or data.frame, lapply(fb.12.unt, summary, na.rm = TRUE) or sapply(fb.12.unt, summary, na.rm = TRUE) might do what you want. BTW: "na.rm=t" is wrong anyway ... Uwe Ligges> It works fine, but I don't know which summary corresponds to which > variable, because the variable names are not printed. Can somebody give > me a hint? > > TIA > > Regards, > > Christoph
Christoph Bier <christoph.bier at web.de> wrote:> how can I tell 'summary' to print the name of the summarised > variable? This is probably an awkward newbie question but I > didn't find an answer in the Docus, the FAQ and maillist archive. > I want a summary for about 250 variables and realise it > the following way (I know, that I shouldn't use iterations > that way in R; but at the moment it's the easiest way for me): > > for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} > > It works fine, but I don't know which summary corresponds to^^^^ This surprises me.> which variable, because the variable names are not printed. > Can somebody give me a hint?Can you give us an example of summary not giving variable names?> df<-data.frame(var1=c(1,2,3),var2=c(4,5,6),factor1=c('a','a','b')) > summary(df)var1 var2 factor1 Min. :1.0 Min. :4.0 a:2 1st Qu.:1.5 1st Qu.:4.5 b:1 Median :2.0 Median :5.0 Mean :2.0 Mean :5.0 3rd Qu.:2.5 3rd Qu.:5.5 Max. :3.0 Max. :6.0> summary(df[1:2])var1 var2 Min. :1.0 Min. :4.0 1st Qu.:1.5 1st Qu.:4.5 Median :2.0 Median :5.0 Mean :2.0 Mean :5.0 3rd Qu.:2.5 3rd Qu.:5.5 Max. :3.0 Max. :6.0 -- Philippe
On Thu, 16 Oct 2003, Christoph Bier wrote:> Hi, > > how can I tell 'summary' to print the name of the summarised > variable? This is probably an awkward newbie question but I > didn't find an answer in the Docus, the FAQ and maillist archive. > I want a summary for about 250 variables and realise it > the following way (I know, that I shouldn't use iterations > that way in R; but at the moment it's the easiest way for me): > > for(i in fb.12.unt[varA1:varZ9]){print (summary(i, na.rm=t))} > > It works fine, but I don't know which summary corresponds to > which variable, because the variable names are not printed. > Can somebody give me a hint?In this context you will have to print the names yourself. summary() doesn't know the names, it only knows the contents of i. summary(a.data.frame) can print the names becuase the names are part of the data frame. As people have already pointed out there are some other strange things about the command. -thomas
Patrick Burns schrieb:> I think you mean na.rm=T by the way.Yes, you're right!> Is > > for(i in whatever) {cat(i, "\n"); print(summary(i, na.rm=TRUE))} > > what you want?No, it doesn't print the value names. I can't tell you why. Philippe wonders, too. In his example the value names are printed. But not with my data frame. Regards, Christoph -- Christoph Bier, Dipl.Oecotroph., Email: bier at wiz.uni-kassel.de Universitaet Kassel, FG Oekologische Lebensmittelqualitaet und Ernaehrungskultur \\ Postfach 12 52 \\ 37202 Witzenhausen Tel.: +49 (0) 55 42 / 98 -17 21, Fax: -17 13