Passing two parameters for application

Say I have a function called

myfun <- function(x,y) {median(x,y)} # obviously the actual function is # something more complicated 

Now, say for some use, the parameter y is constant, say c(1,2,3,4,5) ). Is there a way I can apply this without transferring it to another function? i.e
instead

 apply(mydf, 2, function(x) myfun(x, c(1,2,3,4,5))) 

pass something like

 apply(mydf, 2, myfun(,(c(1,2,3,4,5)))) 

This is purely cosmetic, and I know that it will not make much difference to the operating time. I just want to know if such an option is possible, because every time my function in a function seems to be ineffective.

+4
source share
1 answer

I think this should work:

 apply(mydf, 2, myfun, y = c(1,2,3,4,5)) 

Remains unchecked as I cannot access R right now.

+8
source

Source: https://habr.com/ru/post/1385935/


All Articles