Passing arguments to iterated function through apply

后端 未结 3 691
深忆病人
深忆病人 2020-12-13 18:18

I have a function like this dummy-one:

FUN <- function(x, parameter){
  if (parameter == 1){
      z <- DO SOMETHING WITH \"x\"}
  if (parameter ==2){
         


        
3条回答
  •  悲&欢浪女
    2020-12-13 19:02

    You can make an anonymous function within the call to apply so that FUN will know what "x" is:

    apply(data, 1, function(x) FUN(x, parameter = 1))
    

    See ?apply for examples at the bottom that use this method.

提交回复
热议问题