Skip to content
Prev 6673 / 398500 Next

How to use complicated FUN in apply ?

Jos? Ernesto Jardim wrote:
I think you can construct a new FUN to apply
for example:

fun<-function(x,n){
y_-n/2*log(sum(x^2)/n)
return(y)
}

and then apply it
sigma2.mat<-apply(ri.mat,2,fun)

or use

sigma2.mat<-apply(ri.mat,2, function(x,n){-n/2*log(sum(x^2)/n)} )