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
- Yes you can use any function you like in
FUN
- 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.
- 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 examplemean(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. - Think about what I said earlier:
tidyverse
it will work better withsummarize
- While the
tidyverse
functions will often play fine with base R, they are really designed to work with othertidyverse
functions, and will perform far better doing so.
- While the