1

I want to summarize my dataset by certain columns (Client, Year, LoS, and Country)

This is the desired result

But I don't get this when I use group_by, and then summarize, I get only partial summarization...

What am I doing wrong?

Draken
  • 3,134
  • 13
  • 34
  • 54
Milutin
  • 13
  • 2
  • 4
    Please provide data, code, current and expected output in a copy-pastable format not images. Use `dput(head(df,n))` for data. – NelsonGon Sep 05 '19 at 08:31
  • 1
    See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) how to provide a reproducible example. –  Sep 05 '19 at 08:33
  • 1
    Hi, welcome, please have a look at https://stackoverflow.com/help/minimal-reproducible-example. In order to help you, a reproducible example is useful – Arcoutte Sep 05 '19 at 08:33
  • 1
    In addition to reproducible example, please provide code you have tried, errors, warnings. – zx8754 Sep 05 '19 at 08:35

2 Answers2

-1

I think this should do the trick

library(plyr)
ddply(data, .(Client, Year, LoS, Country), function(x){colSums(x[,5:6]))}
Jarn Schöber
  • 309
  • 1
  • 8
-1

Something like this? Please be more clear on what you need.

data %>%
  group_by(Client, Year, LoS, Country) %>%
  summarise_all("mean", na.rm = TRUE)
Thierry
  • 18,049
  • 5
  • 48
  • 66