[R] Turning pass/fail results into a proportion

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

From: Matthew Walker (m.g.walker@massey.ac.nz)
Date: Wed 26 May 2004 - 15:07:43 EST


Message-id: <40B4261F.9050709@massey.ac.nz>

Please forgive me, I feel exceptionally like a newbie. Although I've
read screeds of documentation, I just can't see how this is done.

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) )

I have found the table() function:

table( df$Var, df$Result)

which potentially seems to be part of the solution, however it turns the
Var column into factors.

As an aside, is the storage of SampleSize (above) the best technique?
Or is it better to store it in a data frame of its own:

data.frame( Var=c(3,4), SamepleSize=c(3,2) )

and then utilise some sort of "lookup" function?

Thank you for your thoughts,

Matthew Walker

______________________________________________
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