-1

I have a dataframe like

count  sample  type
1  DLF002     a
1  DLF002     a
1  DLF002     b
3  DLF001     a
3  DLF001     b
3  DLF001     b

and would like to make a summary given two factor (sample and type), so I would like to have a result like the following

count  sample  type
2  DLF002     a
1  DLF002     b
3  DLF001     a
6  DLF001     b

I have tried something like,

group_by(df, sample) %>% summarize(sx = sum(count)),

but this does not into account the "type"; I wonder how I can make this two level grouping, using dpylr

Areza
  • 5,623
  • 7
  • 48
  • 79

1 Answers1

1

Simply add multiple grouping variables to group_by:

group_by(df, sample, type) %>% summarize(sx = sum(count))
Remko Duursma
  • 2,741
  • 17
  • 24