[R] vector manipulations

Erik Iverson iverson at biostat.wisc.edu
Tue Mar 4 18:44:58 CET 2008


Did you read the help page for 'outer'?

?outer

It says

      'FUN' is called with these two extended vectors as arguments.
      Therefore, it must be a vectorized function (or the name of one),
      expecting at least two arguments.


I don't think your logl function is vectorized according to your summary 
of what you did.


Pete Dorothy wrote:
> Hello,
> 
> I have simulated a set of data which i called "nir" (a vector).
> 
> I have created a function "logl" which calculates the log-likelihood.
> 
> logl is a function of 2 real parameters : "beta" and "zeta" (of length 1).
> 
> This function works perfectly well when I try for example "logl(0.1,0.2)"
> 
> Now if I try :
> 
> "x=seq(0.1,0.5,by=10^(-1))
> y=seq(0.1,0.5,by=10^(-1))
> z=outer(x,y,logl)"
> 
> I get an error.
> 
> The problem seems to be that inside "logl", the following expression is
> calculated : "sum( log( beta+(nir-1)*zeta )  )". So it is a vector
> manipulation. The error tells me that "nir" is not the size of "zeta". Yet
> usually it is no problem since "length(zeta)=1".
> 
> When I replace "sum( log( beta+(nir-1)*zeta ) )" by a loop, I get no
> mistake. But I think it slows down the program.
> 
> Do you have an idea where the problem is ?
> 
> Thank you very much.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list