I'd like to get summary statistics (really just a mean would be fine) for a vector in a data frame, but split based on the value of another vector. That is, I have a data frame (hcd.df) with variables datecat (which is always 1 or 2) and auth.sum (-8..+8). I've used xtabs to get chi-square comparisons, but what I need now is a simple mean of auth.sum where datecat is 1 and another where datecat is 2. Thanks for any advice. ---------------------------------------------------------------------- Andrew J Perrin - andrew_perrin at unc.edu - http://www.unc.edu/~aperrin Assistant Professor of Sociology, U of North Carolina, Chapel Hill 269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "AP" == Andrew Perrin <andrew_perrin at unc.edu> writes:AP> I'd like to get summary statistics (really just a mean would AP> be fine) for a vector in a data frame, but split based on the AP> value of another vector. That is, I have a data frame AP> (hcd.df) with variables datecat (which is always 1 or 2) and AP> auth.sum (-8..+8). I've used xtabs to get chi-square AP> comparisons, but what I need now is a simple mean of auth.sum AP> where datecat is 1 and another where datecat is 2. Thanks for AP> any advice. Something like : lapply(split(hcd.df$auth.sum,hcd.df$datecat),mean) ? -- A.J. Rossini Rsrch. Asst. Prof. of Biostatistics U. of Washington Biostatistics rossini at u.washington.edu FHCRC/SCHARP/HIV Vaccine Trials Net rossini at scharp.org -------------- http://software.biostat.washington.edu/ -------------- FHCRC: M-W: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email UW: T-Th: 206-543-1044 (fax=3286)|Change last 4 digits of phone to FAX Rosen: (Mullins' Lab) Fridays, and I'm unreachable except by email. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Andrew" == Andrew Perrin <andrew_perrin at unc.edu> writes:> I'd like to get summary statistics (really just a mean > would be fine) for a vector in a data frame, but split > based on the value of another vector. That is, I have a > data frame (hcd.df) with variables datecat (which is always > 1 or 2) and auth.sum (-8..+8). I've used xtabs to get > chi-square comparisons, but what I need now is a simple > mean of auth.sum where datecat is 1 and another where > datecat is 2. How about > mean( hcd.df$auth.sum[ hcd.df$datecat==1 ]) > mean( hcd.df$auth.sum[ hcd.df$datecat==2 ]) Or you can use tapply to get means (or summaries or most anything else) for all the levels of datacat: > tapply( hcd.df$auth.sum, hcd.df$datecat, mean ) > tapply( hcd.df$auth.sum, hcd.df$datecat, summary ) Mike -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._