I have a dataframe like this:
id v t1 t2 t3 t4 date1 list1
1 1.0 1.4 2 0.45 3 2020-09-03 val1
1 1.0 1.6 3 0.55 3.7 2020-09-05 val2
How can I group by id, v and aggregate the columns t1, t2, t3, t4, date1, list1 by applying a different aggregate function to each one of them. More specifically
t1 -> mean
t2 -> max
t3 -> mean
t4 -> max
date -> max
list1 -> join as in python's ','.join
So after aggregate the frame looks like:
id v t1 t2 t3 t4 date1 list1
1 1.0 1.5 3 0.5 3.7 2020-09-05 val1, val2
Also one more thing is, these columns could be dynamically added based on a user selection in an R shiny framework, which means all these columns that I intend to aggregate are in the dataframe but some of them may not need to be aggregated, for example user could select only t1, date1 and not the remaining. So my aggregate parameters depend on the selected columns and I do have the column names available from user selection. So probably it makes sense if I ask that how can I build a dynamic aggregate query.
In Python, I could build a dict like the one above dynamically based on user selected columns and use something like pd.agg(**dict)
How can I do this in R? I tried to look at dplyr::summarise and data.table but then I cannot seem to aggregate all of them at once.
smartAgg, which I have not used myself.