Using the customized function within the dplyr verbs

It is almost obvious that there is a need to write customized functions to solve specialized problems. Though there are lots of built-in functions available in base R and also in the specialized libraries, you still might require some kind of output that is not available through the built-in functions. For example, you might want to create a new output dataset by taking only the regression coefficient from a series of linear regression models for the various unique combinations of other variables. In that case, you must write a customized function to achieve this task. The summarize() function from the dplyr library is a convenient way to calculate user-defined statistics. The problem with the summarize() function within the dplyr library is that it can only return single-valued outputs.

In this recipe, you will write a customized function that will calculate the summary statistics (minimum, mean, median, and maximum) of a given variable for different combinations of other variables. The task is to pass the newly defined function through the dplyr functionality which will act like the summarize() function, but can produce multi-valued outputs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset