Re: [R] Turning pass/fail results into a proportion

About this list Date view Thread view Subject view Author view Attachment view

From: Gabor Grothendieck (ggrothendieck@myway.com)
Date: Thu 27 May 2004 - 00:04:57 EST


Message-id: <loom.20040526T160045-168@post.gmane.org>

Matthew Walker <m.g.walker <at> massey.ac.nz> writes:
 
: I have a data frame that contains a number of pass/fails for certain
: variable sizes. From that, I would like to form another data frame that
: contains the proportions of pass/fails per variable.
:
: So, for example:
: df <- data.frame( Var=c(3,3,3,4,4),
: Result=c("pass","fail","fail","pass","pass"), SampleSize=c(3,3,3,2,2))
:
: And I'd like to produce the equivalent of:
: data.frame( Var=c(3,4), ProportionPass=c(0.33, 1) )

Try using aggregate like this:

 aggregate( data.frame(ProportionPass = as.numeric(df$Result)-1),
      list(Var = df$Var), mean)

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:12 EST