[R] Frequency and summary statistics table with different variables and categories

David Winsemius dwinsemius at comcast.net
Thu Jan 22 14:32:56 CET 2009


One of the various tabulation functions would seem to be the most  
appropriate for getting frequency summaries:

?table
?xtabs

On Jan 22, 2009, at 6:17 AM, Stefan Björk wrote:

> Hello helpers,
>
> This is probably quite simple, but I'm stuck.
>
> I want to create a summary statistics table with frequencies and  
> summary
> statistics for a large number of variables. The problem here is that  
> (1)
> there are two different classes of categories (sex, type of  
> substance abuse
> and type of treatent) which overlap, (2) the data for different  
> variables
> should be presented in different ways -- sometimes with relative
> frequencies, other times with mean values.
>
> The table would finally look something like:
>
>                   All  Male  Female Alcohol Drug ...
> Age             (mean) (mean) ...
> Sex (% male)    (freq) (freq) ...
> Alcohol CS      (mean) (mean) ...
> ...              ...
>
> Data is in a data frame with quite a lot of columns (variables) and  
> each row
> represents a single case.
>
> I have found out that part of this can be done with tapply, for  
> example
> tapply(age, sex, mean) and join it with tapply(age, abuse, mean).  
> But how to
> do with frequencies? Or is there an even simpler way?
>
> /S
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list