Quantcast

Percent of a given subset

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Percent of a given subset

jcrosbie

How would I find the Percent of FuelTypeNum within the Band given  AvailableMW?

example:
type 1 is 1%  of PB0
type 2 is 54%  of PB0
 type 4 is 4%  of PB0
 type 5 is 42%  of PB0


Note:   the Bands and fuel types are not always constant.

Data:
FuelTypeNum Bands AvailableMW AvailableMWNewFormat
1 PB0 185319 185.319
2 PB0 18352000 18352
4 PB0 1338785 1338.785
5 PB0 14189756 14189.756
2 PB1 48229 48.229
5 PB1 792433 792.433
2 PB2 7034959 7034.959
4 PB2 796 0.796
5 PB2 1652519 1652.519
1 PB3 16 0.016
2 PB3 11633 11.633
4 PB3 8076 8.076
5 PB3 97410 97.41
1 PB4 4610 4.61
2 PB4 3048 3.048
4 PB4 1117 1.117
5 PB4 28097 28.097
1 PB5 1155 1.155
2 PB5 5331 5.331
4 PB5 2491 2.491
5 PB5 12887 12.887
1 PB6 4 0.004
2 PB6 5774 5.774
4 PB6 2643 2.643
5 PB6 25475 25.475
1 PB7 133 0.133
2 PB7 3787 3.787
4 PB7 750 0.75
5 PB7 10682 10.682
Rdata.xlsx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Percent of a given subset

Rolf Turner-3

There are almost surely a brazillion ways.  Here's one:

Call your data frame "X".  Do:

     XT <- xtabs(AvailableMW~Bands+FuelTypeNum,data=X)
     PXT <- 100*XT/apply(XT,1,sum)
     print(round(PXT,2))

This gives percent of fuel type 1 in band PB0 as

0.54 53.87  3.93 41.65

to two decimal places --- which corresponds with the values
you gave (assuming that you were rather cavalier about rounding).

     cheers,

         Rolf Turner

On 09/06/12 10:15, jcrosbie wrote:

> How would I find the Percent of FuelTypeNum within the Band given
> AvailableMW?
>
> example:
> type 1 is 1%  of PB0
> type 2 is 54%  of PB0
>   type 4 is 4%  of PB0
>   type 5 is 42%  of PB0
>
>
> Note:   the Bands and fuel types are not always constant.
>
> Data:
> FuelTypeNum Bands AvailableMW AvailableMWNewFormat
> 1 PB0 185319 185.319
> 2 PB0 18352000 18352
> 4 PB0 1338785 1338.785
> 5 PB0 14189756 14189.756
> 2 PB1 48229 48.229
> 5 PB1 792433 792.433
> 2 PB2 7034959 7034.959
> 4 PB2 796 0.796
> 5 PB2 1652519 1652.519
> 1 PB3 16 0.016
> 2 PB3 11633 11.633
> 4 PB3 8076 8.076
> 5 PB3 97410 97.41
> 1 PB4 4610 4.61
> 2 PB4 3048 3.048
> 4 PB4 1117 1.117
> 5 PB4 28097 28.097
> 1 PB5 1155 1.155
> 2 PB5 5331 5.331
> 4 PB5 2491 2.491
> 5 PB5 12887 12.887
> 1 PB6 4 0.004
> 2 PB6 5774 5.774
> 4 PB6 2643 2.643
> 5 PB6 25475 25.475
> 1 PB7 133 0.133
> 2 PB7 3787 3.787
> 4 PB7 750 0.75
> 5 PB7 10682 10.682
> http://r.789695.n4.nabble.com/file/n4632857/Rdata.xlsx Rdata.xlsx
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Percent-of-a-given-subset-tp4632857.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Percent of a given subset

David Winsemius
In reply to this post by jcrosbie

On Jun 8, 2012, at 6:15 PM, jcrosbie wrote:

>
> How would I find the Percent of FuelTypeNum within the Band given
> AvailableMW?
>
> example:
> type 1 is 1%  of PB0
> type 2 is 54%  of PB0
> type 4 is 4%  of PB0
> type 5 is 42%  of PB0

format( 100*prop.table(table(dfrm$FuelTypeNum)), 0 )

...  should do it.

>
>
>
> Note:   the Bands and fuel types are not always constant.
>
> Data:
> FuelTypeNum Bands AvailableMW AvailableMWNewFormat
> 1 PB0 185319 185.319
> 2 PB0 18352000 18352
> 4 PB0 1338785 1338.785
> 5 PB0 14189756 14189.756
> 2 PB1 48229 48.229
> 5 PB1 792433 792.433
> 2 PB2 7034959 7034.959
> 4 PB2 796 0.796
> 5 PB2 1652519 1652.519
> 1 PB3 16 0.016
> 2 PB3 11633 11.633
> 4 PB3 8076 8.076
> 5 PB3 97410 97.41
> 1 PB4 4610 4.61
> 2 PB4 3048 3.048
> 4 PB4 1117 1.117
> 5 PB4 28097 28.097
> 1 PB5 1155 1.155
> 2 PB5 5331 5.331
> 4 PB5 2491 2.491
> 5 PB5 12887 12.887
> 1 PB6 4 0.004
> 2 PB6 5774 5.774
> 4 PB6 2643 2.643
> 5 PB6 25475 25.475
> 1 PB7 133 0.133
> 2 PB7 3787 3.787
> 4 PB7 750 0.75
> 5 PB7 10682 10.682
> http://r.789695.n4.nabble.com/file/n4632857/Rdata.xlsx Rdata.xlsx
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Percent-of-a-given-subset-tp4632857.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Loading...