Is this what you want:
> x <- by(frame, list(frame$p.a, frame$p.b), function(.row){
+ c(f=sum(.row$r)/ nrow(.row), p.a=.row$p.a[1],
p.b=.row$p.b[1],freq=nrow(.row))
+ })> do.call(rbind, x)
f p.a p.b freq
[1,] 0.50 10 2 2
[2,] 0.50 20 3 2
[3,] 0.25 50 5 4
On Thu, May 22, 2008 at 4:26 PM, Hugh Kingston
<hwfkingston@googlemail.com>
wrote:
> Dear All,
>
> I would be most grateful for help on this problem.
>
> I have a binary response variable. It is classified by various factors.
> I would like to have a table with;
>
> column 1
> frequency response is 1 / (frequency the response is 1 + frequency the
> response is 0) #given the classifying factors are the same
>
> column 2...(n-1)
> states of classifying factors
>
> column 3
> (frequency the response is 1 + frequency the response is 0)
>
>
> I want to do this to reduce the size of my table so i can use it for
> logistic regression without running out of memory.
>
> some example data to illustrate the problem;
> response <- c(0,1,0,1,0,0,0,1)
> predictor.a <- c(10,10,20,20,50,50,50,50)
> predictor.b <- c(2,2,3,3,5,5,5,5)
> frame <- data.frame(r = response, p.a = predictor.a, p.b = predictor.b)
>
> > frame
> r p.a p.b
> 1 0 10 2
> 2 1 10 2
> 3 0 20 3
> 4 1 20 3
> 5 0 50 5
> 6 1 50 5
>
> desired result........
> f p.a p.b freq
> 0.5 10 2 2
> 0.5 20 3 2
> 0.25 50 5 4
>
>
> many thanks,
>
> Hugh
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
[[alternative HTML version deleted]]