[R] How to use complicated FUN in apply ?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Aug 4 13:47:48 CEST 2000


José Ernesto Jardim <ernesto at ipimar.pt> writes:

> 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 ?!

Yes and yes... That syntax means that you want to use a function
called "-n/2*log(sum(ri.mat^2)/n)". I think you mean 

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

(assuming that the variable "n" exists, otherwise you might something
like function(x){n<-length(x); -n/2*log(sum(x^2)/n)} )
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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