Hi I am writing a function where my input can take a list of functions like this
temp(mean,sum...)
and the function looks like this:
temp <- function(funs = NULL){
mtcars %>%
dplyr::group_by(cyl) %>%
dplyr::summarise_if(is.numeric,funs,na.rm =TRUE)
}
the output will has xx_fn1, xx_fn2 etc but I want the column names to be xx_mean,xx_sum.
Tried deparse(substitute(funs))
but nothing works.
Plz help!
The function is ok (apart from misspelled mtcars
name I think). You just need to use funs()
function on your functions (just like in summarise_if()
), eg
temp(funs(mean = mean))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.