Skip to content

Descriptive statistics table

5 messages · Mihai Nica, Uwe Ligges, Brian Ripley +2 more

#
Mihai Nica wrote:

            
Well, summary(df) already does it.
If you want something different, see the code of summary() (simply type: 
summary.data.frame) as an example ...

Uwe Ligges
#
On Sun, 17 Oct 2004, Mihai Nica wrote:

            
Please check ?apply: it applies to matrices, not data frames.

Try sapply(mydf, summary) and extract the info you want, or write your own 
summary function such as

sapply(mydf, function(x) c(mean=mean(x), median=median(x)))
#
Mihai Nica wrote:

            
Apart from Uwe's advice of reading summary.data.frame,
here is a very simple version:

 > test <- data.frame(x=rnorm(100), y=rnorm(100), z=rnorm(100))
 > sapply(test, function(x) {
            res <- c(mean(x), median(x), mad(x), sd(x))
            names(res) <- c("mean","median","mad","sd")
            res}
  )
               x          y           z
mean   0.2159557 0.01684044 -0.05950480
median 0.1123084 0.13149150  0.01451704
mad    1.0054574 0.91742137  1.16986352
sd     0.8999813 0.98771362  1.02901577

Kjetil
#
Mihai Nica wrote:
Besides a standard summary( ), one of many ways is to use the Hmisc 
package.  See 
http://biostat.mc.vanderbilt.edu/s/Hmisc/html/summary.formula.html
http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatReport/summary.pdf 
http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/SdataManip