Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-28 Thread Greg Snow
lD > Sent: Saturday, June 26, 2010 10:47 PM > To: r-help@r-project.org > Subject: Re: [R] Calculating Summaries for each level of a Categorical > variable > > > Hi Corey, > > Thanks so much for this. However, I get this error for tapply - "Error > in > ta

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread Christos Argyropoulos
   46/51/57|  46/48/52|  49/54/60|   F=2.9 d.f.=3,16 P=0.068  | +--+--+--+--+--+--++   > Date: Sat, 26 Jun 2010 21:48:05 -0700 > From: raoul.t.dso...@gmail.com > To: r-h

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread David W Freedman
I'd suggest using the functions within the Hmisc and plyr packages: library(Hmisc); library(plyr) df=data.frame(v1=rnorm(10), v2=rnorm(10), wt=sample(1:5,rep=T),sex=rep(0:1,each=5)); df ddply(df,~sex,summarise,v1.avg=wtd.mean(v1,wt),v2.avg=wtd.mean(v2,wt)) hope this helps, david freedman -- Vi

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread Corey Sparks
the variable you want to analyze (first argument to tapply) and the variable you want to analyze by (the factor, second arg to tapply) both must have the same number of rows, that' s how I read this. CS Corey Sparks Assistant Professor Department of Demography and Organization Studies College

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread David Hajage
You could try the remix function in remix package. David Le 27 juin 2010 à 06:48, RaoulD a écrit : > > Hi Christos, > > Thanks for this. I had a look at Summary.Forumla in the Hmisc > package and it > is extremely complicated for me. Still trying to decipher how I > could use > it. > > Regards,

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread RaoulD
Hi Corey, Thanks so much for this. However, I get this error for tapply - "Error in tapply(RT, RT$R, fun=WA): arguments must have same length". Any idea how to get around this? Thanks again, Raoul -- View this message in context: http://r.789695.n4.nabble.com/Calculating-Summaries-for-each-

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-27 Thread RaoulD
Hi Christos, Thanks for this. I had a look at Summary.Forumla in the Hmisc package and it is extremely complicated for me. Still trying to decipher how I could use it. Regards, Raoul -- View this message in context: http://r.789695.n4.nabble.com/Calculating-Summaries-for-each-level-of-a-Catego

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-26 Thread Christos Argyropoulos
Look at the summary.formula function inside package Hmisc Christos > Date: Sat, 26 Jun 2010 05:17:34 -0700 > From: raoul.t.dso...@gmail.com > To: r-help@r-project.org > Subject: [R] Calculating Summaries for each level of a Categorical variable > > > Hi, > > I

[R] Calculating Summaries for each level of a Categorical variable

2010-06-26 Thread RaoulD
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

Re: [R] Calculating Summaries for each level of a Categorical variable

2010-06-26 Thread Corey Sparks
Did you try tapply? ?tapply tapply(RT, RT$R, fun=WA) or something like that - Corey Sparks, PhD Assistant Professor Department of Demography and Organization Studies University of Texas at San Antonio 501 West Durango Blvd Monterey Building 2.270C San Antonio, TX 78207 210-458-3166 corey.sp