[R] function pointer question

Giovanni Azua bravegag at gmail.com
Mon Apr 26 09:13:44 CEST 2010


Hello Jan,

On Apr 26, 2010, at 8:56 AM, Jan van der Laan wrote:
> You can use the '...' for that, as in:
> 
> loocv <- function(data, fnc, ...) {
> n <- length(data.x)
> score <- 0
> for (i in 1:n) {
>   x_i <- data.x[-i]
>   y_i <- data.y[-i]
>   yhat <- fnc(x=x_i,y=y_i, ...)
>   score <- score + (y_i - yhat)^2
> }
> score <- score/n
> return(score)
> }
> 
> scoreks <- loocv(data,gaussiankernel, h=0.5)

It works nicely, thank you!

Best regards,
Giovanni



More information about the R-help mailing list