[R] numerical summaries across variables.

Jim Lemon jim at bitwrit.com.au
Tue Sep 1 12:07:15 CEST 2009


rajclinasia wrote:
> Hi Every one,
> I have a dataframe "class" with "name", "sex", "age", "height", "Weight".
> if i caluclate summary statistics with the below code
>
> numSummary(class[,c("Height", "Weight")], groups=class$Name,
> statistics=c("mean", "sd", "quantiles"), quantiles=c(0,
>   .25,.5,.75,1))
>
> iam getting output like this
>
> Variable: Height 
>         mean sd   0%  25%  50%  75% 100% n
> Alfred  69.0 NA 69.0 69.0 69.0 69.0 69.0 1
> Alice   56.5 NA 56.5 56.5 56.5 56.5 56.5 1
> Barbara 65.3 NA 65.3 65.3 65.3 65.3 65.3 1
> Carol   62.8 NA 62.8 62.8 62.8 62.8 62.8 1
>
> Variable: Weight 
>          mean sd    0%   25%   50%   75%  100% n
> Alfred  112.5 NA 112.5 112.5 112.5 112.5 112.5 1
> Alice    84.0 NA  84.0  84.0  84.0  84.0  84.0 1
> Barbara  98.0 NA  98.0  98.0  98.0  98.0  98.0 1
> Carol   102.5 NA 102.5 102.5 102.5 102.5 102.5 1
>
> now my question is i want output like this 
>
>                       height         weight
> Alfred mean 
>          sd    
>          0%   
>          25%   
>          50%   
>          75%  
>          100% 
>           n
> Alice mean 
>          sd    
>          0%   
>          25%   
>          50%   
>          75%  
>          100% 
>           n
> Barbara mean 
>          sd    
>          0%   
>          25%   
>          50%   
>          75%  
>          100% 
>           n
>
>  it is nothing but a numerical summaries across varibales. is it possible.
>
>   
Hi Raj,
I think you may have to write a print function for this. Assign the 
result of numSummary to an object, use "str" to find out the structure 
and then use "cat" to display the bits in the format you want. I don't 
have Rcmdr on my system and haven't been able to install it as R refuses 
to believe that I have Tcl-Tk available. Thus I can't tell you exactly 
how to do this.

Jim




More information about the R-help mailing list