[R] Descriptive statistics table

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Oct 17 18:51:10 CEST 2004


On Sun, 17 Oct 2004, Mihai Nica wrote:

> Greetings:
> 
> I would like to make a table with descriptive statistics for a data.frame. I guess the question is how can I put together, in a table, the results from, say:
> 
> apply(df, 2, mean, na.rm =T)
> apply(df, 2, median, na.rm =T)
> .......

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)))

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list