Thank you, but I believe that's not returning what I want.Â
This maybe a better dat aset to work with.Â
seq1 = seq(0, 100, by = 5)Â
seq2 = seq(100, 1000, by = 100)Â
Bands = c(seq1, seq2)Â
DF1 <- data.frame(matrix(ncol = 2, 200))
colnames(DF1)<- c("Price", "Size")
DF1$Price <_ sample(1:1000, 200, replace=F)Â
DF1$Size <_ sample(1:1000, 200, replace=F)
I'm looking to find the subtotal of size when their price falls within a band.Â
The bands go 0 to 5, 5 to 10,....100 to 200,..., 900 to 1000.Â
Therefore if we had:
Price Size
210
220
1120
1120
The total in this case would be
0 to 5Â 30
10 to 2040
Thank you
________________________________
From: arun kirshna [via R] <[email protected]>
To: jcrosbie <[email protected]>
Sent: Wednesday, October 17, 2012 10:32 AM
Subject: Re: subtotals based on price bands?
Hi,
May be this helps:
seq1 = seq(0, 100, by = 5)
seq2 = seq(100, 1000, by = 100)
Bands = c(seq1, seq2)
set.seed(1)
Prices = sample(1:1000, 200, replace=F)
set.seed(1)
size = sample(1:1000, 200, replace=F)
Prices1<-cut(Prices,breaks=unique(Bands))
 tapply(size,Prices1,sum)
# Â Â Â (0,5] Â Â Â (5,10] Â Â (10,15] Â Â (15,20] Â Â (20,25] Â Â
(25,30]
 #    NA      NA      26      NA    Â
 23      NA
  #(30,35]   (35,40]   (40,45]   (45,50]   (50,55]  Â
(55,60]
   #  31      NA      NA      NA    Â
 54      NA
  #(60,65]   (65,70]   (70,75]   (75,80]   (80,85]  Â
(85,90]
   #  126      67      NA      79    Â
 82     179
  #(90,95]   (95,100]  (100,200]  (200,300]  (300,400] Â
(400,500]
   #  186      NA     2627     5342   Â
 8927     9961
 #(500,600]  (600,700]  (700,800]  (800,900] (900,1e+03]
  #  10932    14913    18677    12833    16022
table(Prices1)
#Prices1
  #  (0,5]    (5,10]   (10,15]   (15,20]   (20,25]  Â
(25,30]
   #   0      0      2      0   Â
  1      0
  #(30,35]   (35,40]   (40,45]   (45,50]   (50,55]  Â
(55,60]
   #   1      0      0      0   Â
  1      0
  #(60,65]   (65,70]   (70,75]   (75,80]   (80,85]  Â
(85,90]
   #   2      1      0      1   Â
  1      2
  #(90,95]   (95,100]  (100,200]  (200,300]  (300,400] Â
(400,500]
   #   2      0      17      22   Â
  25      22
 #(500,600]  (600,700]  (700,800]  (800,900] (900,1e+03]
  #   20      23      25      15    Â
 17
A.K.
________________________________
If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/subtotals-based-on-price-bands-tp4646473p4646484.html
This email was sent by arun kirshna (via Nabble)
To receive all replies by email, subscribe to this discussion
--
View this message in context:
http://r.789695.n4.nabble.com/subtotals-based-on-price-bands-tp4646473p4646505.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.