[R] summary with names

Philippe Glaziou glaziou at pasteur-kh.org
Thu Oct 16 13:56:41 CEST 2003


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




More information about the R-help mailing list