[R] calculation fraction/ratio

From: YIHSU CHEN <yihsuc_at_gmail.com>
Date: Fri, 1 Feb 2008 15:19:16 -0800


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_at_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. Received on Sat 02 Feb 2008 - 10:13:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 02 Feb 2008 - 13:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive