Finding the Count Sum by range buckets

Hi All,

Hope you are doing well!..I am trying to find the count Sum by order bucket values... Please find the data below: Can you please help me here...Basically sum of the order_count by order value bucket..

tibble::tribble(
~order_count, ~order_bucket,
681, "100 to 1000",
306, "100 to 1000",
136, "100 to 1000",
141, "100 to 1000",
55, "0 to 100",
26, "0 to 100",
97, "0 to 100",
7457, "1000+",
37, "0 to 100",
47, "0 to 100",
11, "0 to 100",
9, "0 to 100",
230, "100 to 1000",
28, "0 to 100",
141, "100 to 1000",
72, "0 to 100",
1536, "1000+",
2421, "1000+",
49, "0 to 100",
10209, "1000+",
24, "0 to 100",
45, "0 to 100",
10, "0 to 100",
41, "0 to 100"
)

Thanks,
Arun

Is this what you're looking for?

library(tidyverse)

df <- tribble(
  ~order_count, ~order_bucket,
  681, "100 to 1000",
  306, "100 to 1000",
  136, "100 to 1000",
  141, "100 to 1000",
  55, "0 to 100",
  26, "0 to 100",
  97, "0 to 100",
  7457, "1000+",
  37, "0 to 100",
  47, "0 to 100",
  11, "0 to 100",
  9, "0 to 100",
  230, "100 to 1000",
  28, "0 to 100",
  141, "100 to 1000",
  72, "0 to 100",
  1536, "1000+",
  2421, "1000+",
  49, "0 to 100",
  10209, "1000+",
  24, "0 to 100",
  45, "0 to 100",
  10, "0 to 100",
  41, "0 to 100"
)

df %>% 
  group_by(order_bucket) %>% 
  summarize(order_sum = sum(order_count))
#> # A tibble: 3 x 2
#>   order_bucket order_sum
#>   <chr>            <dbl>
#> 1 0 to 100           551
#> 2 100 to 1000       1635
#> 3 1000+            21623

Created on 2020-02-26 by the reprex package (v0.3.0)

Thanks Siddharth!..Appreciate your help!..

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.