Skip to content

my own function given to lapply

3 messages · Christoph Lehmann, Jeff Gentry, Marc Schwartz

#
Hi 

It seems, I just miss something. I defined 

treshold <- function(pred) {
if (pred < 0.5) pred <- 0 else pred <- 1
return(pred)
}

and want to use apply it on a vector

sapply(mylist[,,3],threshold)

but I get:

Error in match.fun(FUN) : Object "threshold" not found

thanks for help
cheers

chris
#
^^^^^^^^
^^^^^^^^^

If this is a direct cut & paste, you have a typo as you've defined the
function as "treshold".
#
On Thu, 2004-02-26 at 11:39, Christoph Lehmann wrote:
Perhaps the missing first 'h' in the 'treshold' function definition
would be the problem?

Alternativey, you need to use:

sapply(mylist[, , 3], treshold)

HTH,

Marc Schwartz