Re: [R] function pointer question

2010-04-26 Thread Giovanni Azua
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 +

Re: [R] function pointer question

2010-04-25 Thread Jan van der Laan
Giovanni, 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 <- l

Re: [R] function pointer question

2010-04-25 Thread Giovanni Azua
The beauty of trial and error ... if I leave the non x, y parameters i.e. h as global parameters rather than formal parameters for gaussiankernel it works fine basically I don't pass anymore h=0.5 to gaussiankernel but consume it from a global variable. Ugly but works ... Best regards, Giovanni

[R] function pointer question

2010-04-25 Thread Giovanni Azua
Hello, I have the following function that receives a "function pointer" formal parameter name "fnc": 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