Hi,
this is a made-up example. Function myfun returns two arguments. Can
apply be used so that myfun is called only once?
Thanks
Serguei
mat-matrix(runif(50),nrow=10,ncol=5)
myfun-function(x) {
mymean-mean(x)
mysd-sd(x)
return(mymean,mysd)
}
out1-t(apply(mat,1,function(x)
Yes. Just try it and see.
BTW, your usage of return() is not recommended anymore. This is
probably easier:
myfun-function(x) c(mean=mean(x), sd=sd(x))
out - apply(mat, 1, myfun)
## or...
out2 - cbind(mean=rowMeans(mat), sd=sd(t(mat)))
Andy
From: Serguei Kaniovski
Hi,
this is a