0

I have this table I am working with.

rent_data <- data.frame(id = c(123,124,125,126,127,128,129,123),
            desc = c("Rent Payment", "Rent Payment", "Late Fee", "Pet Fee", "Rent Payment", "Late Fee", "Pet Fee", "Rent Payment" ),
            units = c(1,2,1,2,4,1,1,2),
            total_dol = c(500,1000,250,600,2000,250,300,500))

> print(rent_data)
   id         desc units total_dol
1 123 Rent Payment     1       500
2 124 Rent Payment     2      1000
3 125     Late Fee     1       250
4 126      Pet Fee     2       600
5 127 Rent Payment     4      2000
6 128     Late Fee     1       250
7 129      Pet Fee     1       300
8 123 Rent Payment     2       500

My goal is to get a frequency table that shows me the sum of units and total_dol broken down by 'desc' column. I'm hoping to get a solution with dplyr/tidyverse.

My desired output. Thank you.

enter image description here

RL_Pug
  • 697
  • 7
  • 30
  • `rent_data %>% group_by(desc) %>% summarise(across(c(units, total_dol), sum))` – Ronak Shah Oct 26 '21 at 13:21
  • Is there a particular difference between what you put and this? rent_data %>% group_by(desc) %>% summarise( units = sum(units), total_dol = sum(total_dol) ) – RL_Pug Oct 26 '21 at 13:22
  • No, not really. `across` is used to avoid writing the same thing multiple times. – Ronak Shah Oct 26 '21 at 13:27

0 Answers0