R wrapper function
1 answer
Let's say I want to use mean()
, but I want to set some default arguments, and my usecase does not allow additional arguments to be added when I actually call mean()
.
I could create a wrapper function:
mean_noNA <- function(x) {
return(mean(x, na.rm = T))
}
mean_noNA
is a wrapper for mean()
where we set it na.rm
to TRUE.
Now we can use mean_noNA(x)
the same as mean(x, na.rm = T)
.
+6
source to share