[R] subtotals based on price bands?

Ista Zahn istazahn at gmail.com
Wed Oct 17 22:42:50 CEST 2012


Hi,

How about

dat <- data.frame(Prices, size, Band = cut(Prices, breaks=unique(Bands)))
by(dat$size, dat$Band, sum)

Best,
Ista

On Wed, Oct 17, 2012 at 10:58 AM, jcrosbie <james at crosb.ie> wrote:
> I would like to create a subtotal table with custom bands.
>
> seq1 = seq(0, 100, by = 5)
> seq2 = seq(100, 1000, by = 100)
> Bands = c(seq1, seq2)
> #Prices
> Prices = sample(1:1000, 200, replace=F)
> #corresponding size for the given price above.
> size = sample(1:1000, 200, replace=F)
>
> How would  I find the subtotal of the size based on a given price falls
> within a band?
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/subtotals-based-on-price-bands-tp4646473.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.




More information about the R-help mailing list