kirkegaard icon indicating copy to clipboard operation
kirkegaard copied to clipboard

df_merge_rows: multi-function approach

Open Deleetdk opened this issue 7 years ago • 0 comments

Instead of supplying a single function that must work for all columns or all numeric columns, make it so one supplies either a function or a list of functions. If a function, it will be used on all columns. If a list of functions, it will use any function that matches the column name. If there is none, it will default to one for that type. This is a clever approach to handling mixed data data frames.

The default func should be something like:

list(.numeric = wtd_sum, .default = first_row)

So, given a column, it is tested for numerical status (integer or double). If yes, then the values are summed. If not, it defaults to .default and takes the first row. In this way, every column is processed. One can make it possible for there to be no function that applies, which raise an error that may be useful in some cases.

Deleetdk avatar Jan 30 '17 11:01 Deleetdk