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) ....... Thanks, Mihai Nica Jackson State University 155 B Parkhurst Dr. Jackson, MS 39202 601 969 5423 601 914 0361 [[alternative HTML version deleted]]
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) > .......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> Thanks, > > Mihai Nica > Jackson State University > 155 B Parkhurst Dr. > Jackson, MS 39202 > 601 969 5423 > 601 914 0361 > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
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
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) >....... > >Thanks, > >Mihai Nica >Jackson State University >155 B Parkhurst Dr. >Jackson, MS 39202 >601 969 5423 >601 914 0361 > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > >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 -- Kjetil Halvorsen. Peace is the most effective weapon of mass construction. -- Mahdi Elmandjra
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) > ....... > > Thanks, > > Mihai Nica > Jackson State University > 155 B Parkhurst Dr. > Jackson, MS 39202 > 601 969 5423 > 601 914 0361 > [[alternative HTML version deleted]]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 -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University