[R] How to use complicated FUN in apply ?

Alvaro Colina acosa at ubu.es
Fri Aug 4 14:00:01 CEST 2000


José Ernesto Jardim wrote:
> 
> Hi everyone
> 
> I'm trying to use
> 
> sigma2.mat<-apply(ri.mat,2,'-n/2*log(sum(ri.mat^2)/n)')
> 
> but it's not working.
> 
> Is it wrong to use that kind of FUN in apply ? or am I doing something
> wrong ?!

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)} )



-- 

==============================================================
Alvaro Colina    		|-|o||o||o||o||o||o||o||o||o|- 
Area de Quimica Analitica	| Pza. Misael Banuelos s/n
Facultad de Ciencias		| 09001. Burgos. Spain
Universidad de Burgos		| Phone: 34-947-258817
e-mail: acosa at ubu.es	  	| FAX: 	 34-947-258831
==============================================================
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list