Skip to content
Prev 30900 / 398506 Next

how to use apply with a function created by ourselfs...?

"ANA KOZOMARA" <magnolia at absolutok.net> writes:
It depends on your prediction function. The best thing is to arrange
that it vectorizes over its arguments, as Spencer Graves suggested.
Then it's just 

prediction(df[,1],df[,2])

or, if you want something that works for more than two rows,

do.call("prediction", df) 

if your prediction() does not vectorize (i.e. a and b has to be
scalars), you can do two things:

pr.row <- function(row) do.call("prediction",row)
apply(df, 1, pr.row)

or create a vectorized prediction(), as in 

pr.vec <- function(a,b)
   sapply(seq(along=a),function(i)prediction(a[i],b[i]))