Dear R users

I wonder if there is a quick way to calculate the ratio/fraction of a
list/data frame.  For example, if I have a data frame with two fields:
"Index" and "A".  I would like to know the fractions of A's within the same
"Index".   That is, for Index =1, three fractions will be "1/(1+2+3)=0.17",
"2/(1+2+3)=0.33", and "3/1+2+3=0.5".   Likewise for Index =2 and Index 3.
So, I then generate a new vector of 0.17, 0.33, 0.5... ,etc.


 Index A  1 1  1 2  1 3  2 4  2 3  3 7  3 9  3 3  3 1

Thank you so much

Yihsu

        [[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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to