[R] problems with outer
Faheem Mitha
faheem at email.unc.edu
Sun May 7 03:57:48 CEST 2000
On 7 May 2000, Peter Dalgaard BSA wrote:
> Faheem Mitha <faheem at email.unc.edu> writes:
>
> > Note that my function tempexpbinsumsq merely exists for the purpose of
> > outer. I could have done
> > tempmatrix <-
> > outer(x,y,function(x,y) expbinsumsq(point,pair,x,y,a,b,theta))
> > but I don't know if that would be correct usage.
> >
> > Can someone explain what is going on? I'm at my wits end.
>
> The thing that usually tricks beginners with outer() is that the
> function has to be vectorised. I.e. if you stick in vectors for x and
> y, you get a vector result back. Otherwise, you have to vectorise it
> yourself, e.g. if f takes scalar arguments,
>
> f.vect <- function(x,y) sapply(seq(along=x),function(i)f(x[i],y[i]))
This is helpful. However I'd like to clarify the meaning of vectorisation
in this case.
Does a vectorised function with two arguments mean that if X, Y vectors
then f(X,Y)= (f(X_i,Y_i)), ie f(X,Y) is the vector with component
f(X_i,Y_i)?
This is what appears to be the case from the line beginning f.vect above.
In particular, this would force x and y to be the same length. If this is
not the case then I am puzzled how f.vect would be what I want.
A priori, I could have taken this to mean that f must satisfy the
following:
If X is a vector, and y is a scalar, then f(X,y) = (f(X_i,y)) ie f(X,y) is
the vector with components (f(X_i,y) and similarly for f(x,Y). But this is
not what you mean, is it?
Please excuse any confusion. Trying to debug stuff always wears me out, so
I am not at my best right now.
Thanks. Faheem.
--
> 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