Combining sapply() with group_by()

,

First of all it feels like I might be doing you homework for you? If this is an assignment (which is fine - this community is here to help) please read this

  1. Yes you can use any function you like in FUN
  2. Doing it as you are, is using an "anonymous" function - you might find it easier to visualize if you pull the function out and create a standalone function.
  3. Some functions (eg summary) are quite happy to work on a dataframe. Othere like 'mean / 'median etc will only work on a vector, so you can say for example mean(iris[1:4]).
    . To do what you are doing you would have to loop over each column, then loop over each function, while looping over each group of the data - doable but troublesome.
  4. Think about what I said earlier: tidyverse it will work better with summarize
    • While the tidyverse functions will often play fine with base R, they are really designed to work with other tidyverse functions, and will perform far better doing so.