[R] outer problem
Erich Neuwirth
erich.neuwirth at univie.ac.at
Tue Jun 20 19:52:16 CEST 2000
thank you,
i also looked into the definition of outer and now i understand what is
happening.
but now i have some more questions
on how to vectoruce functions.
lapply and sapply essentially allow to vectorise a fucntion with one
argument.
but is there a way of vectorizing a 2 argument function such that
the 2 arguments lists are "run through" sybchronously?
in lisp
(mapcar (lambda (x y) (* x y)) (1 3 5) (2 4 6))
produces the list (1*2 3*4 5*6)
(not really, this is just a description of hiw it works).
lapply and sapply accept more than one list arguments,
but then work on the cross product.
lapply(1:3,2:4,FUN=function(x,y)x*y)
sapply(1:3,2:4,FUN=function(x,y)x*y)
will returns lists and arrays with 9 elements, not with 3 elements.
is there a "natural" way of running through lists in sync, like mapcar
does?
> You're misunderstanding outer().
>
> outer(x,y,f) does just one call to f with arguments created by stacking x
> and y together in the right way, so f has to be vectorised.
>
> In any case, var(X) returns the covariance matrix of X, much more
> efficiently.
>
> -thomas
>
> Thomas Lumley
> Assistant Professor, Biostatistics
> University of Washington, Seattle
--
Erich Neuwirth, Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-38624 Fax: +43-1-4277-9386
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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