Skip to content
Prev 334103 / 398513 Next

Need help figuring out sapply (and similar functions) with multiple parameter user defined function

Read the documentation more closely: sapply(dataFrame, func)
applies func() to each column, not row, of dataFrame.
Furthermore,
    sapply(X = dataFrame, FUN = func, extraArgument)
calls
    func(dataFrame[, i], extraArgument)
for i in seq_len(ncol(dataFrame).

One problem is that FUN=evaluate.questions takes 3 arguments and
you give it only 2.  Another problem is that the third argument you
pass to sapply is a function (of 3 arguments) and FUN is not expecting
any of its arguments to be functions.

It may be easier for you to not use sapply here, but to use for-loops and
come up with something that works.  (Write tests that will indicate whether
it works or not in a variety of situations.)  Then transform it to use things
like ifelse() and sapply() to make it more readable and run faster.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com