
Look at the summary.formula function inside package Hmisc

Christos

> Date: Sat, 26 Jun 2010 05:17:34 -0700
> From: raoul.t.dsouza@gmail.com
> To: r-help@r-project.org
> Subject: [R] Calculating Summaries for each level of a Categorical variable
> 
> 
> Hi,
> 
> I have a dataset which has a categorical variable "R",a count variable C
> (integer) and 4 or more numeric variables (A,T,W,H - integers) containing
> measures for "R". I would like to summarize each level of the variable R by
> the average for A,T,W and H. 
> 
> I have written a function to calculate weighted averages using C as the
> weight and this is given below. The function works perfectly but how do I
> add the additional dimension I require to this function?
> 
> Dataset: RT=
> R     A  T   W   H
> R1   10 20 20  10
> R2   60 20 50  10
> R3   45 10 20  50
> R4   68 50 20  10
> R1   73 20 40  46
> R3   25 30 10  54
> R3   36 90 20  10
> R2   29 10 30  30
> 
> # FUNCTION TO CALCULATE THE WEIGHTED AVERAGE FOR A WEIGHTED BY C
> WA<-function(A,C) {
>          sp_A<-c(A %*% C)
>          sum_C<-sum(C)
>          WA<-sp_A/sum_C   
>          return(WA)      
>          }
> 
> I am trying to incorporate the additional step of calculating the weighted
> average of A,T,W and H for each level of R. Need help with this.
> 
> Thanks in advance!
> Raoul
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Calculating-Summaries-for-each-level-of-a-Categorical-variable-tp2269349p2269349.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help@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.
 		 	   		  
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.

	[[alternative HTML version deleted]]

