[R] how to make a table of summary statistics

Jim Lemon jim at bitwrit.com.au
Fri Dec 21 03:15:57 CET 2012

On 12/20/2012 10:45 PM, Francesco Sarracino wrote:
> Dear R-listers,
> I am a newbie with R and I am struggling with something I consider very
> basic. I wish to produce a table (to import in a latex file) of summary
> statistics, but for as much as I've been looking around and trying various
> alternatives (plyr, reporttools, pastecs and Hmisc) I haven't found what I
> am looking for. Probably I am doing something wrong, but I can't figure out
> what.
> Let's make up three simple variables:
> var1<- runif(1000)
> var2<- runif(1000)
> var3<- factor(rep(1:2, 500), labels = c("m", "f"))
> and let's create a dataset out of them:
> data<- data.frame(var1, var2, var3)
> what I'd like to get is a table such as the following one:
> variable mean sd min max obs missing
> var1
> var2
> var3
> where for each variable, I can read in line the mean, the standard
> deviation, the min and the max values, the number of observations and the
> percentage of missing data.

Hi Francesco,
Have a look at the describe function (prettyR) that allows you to select 
the summary statistics you want for numeric variables and automatically 
produces count statistics for factor, character and logical variables. 
There are also other "auto-summarize" functions in packages such as 
psych and Hmisc.


More information about the R-help mailing list