0

I have a code for the pivot table that looks like this:

var1 var2 var3 Sum_in_items Sum_in_money
First First 1 10 500
Second Second 2 12 500

And it looks like this:

db %>%                        
  group_by(var1, var2, var3) %>%
  dplyr::summarise(Sum_in_items = round(sum(items)), 
                   Sum_in_money = sum(money))

However, I also have var4 which has several levels (var1, var2, and var3 are also factors) and I need to add these levels of var4 as columns to the table. It should look like in the photo. I am sorry I cannot create the table here. The photo of desired output

I am super new at pivot tables and my formulations might be strange, please ask questions if you have any. I know how to do such thing in tableau (I just drag var4 into columns but here it is harder).

  • Is the first table you provided `db` or is that table the result of the following code? Can you provide your entire dataset or produce a reproducible example that includes `var4`? See here: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jrcalabrese May 02 '23 at 15:22

0 Answers0