Re: [R] How to convert two-dimensional function to matrix?

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Wed 02 Aug 2006 - 01:06:55 EST

JeeBee <JeeBee@troefpunt.nl> writes:

> On Tue, 01 Aug 2006 16:23:46 +0200, Lothar Schmid wrote:
>
> > I'd like to convert a two-dimensional function f(x,y) to a matrix m,
> > so that m[x,y] = f [x,y]. How can I achieve this?
>
> Maybe this helps.
> I create an empty matrix first, then apply f to the indices.
>
> f <- function(x, y) { 1000*x + y }
>
> ( m <- matrix( data = NA, nrow = 5, ncol = 4 ) )
> ( m <- f(row(m), col(m)) )

outer(1:5, 1:4, f)

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Wed Aug 02 01:14:58 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 02 Aug 2006 - 02:17:41 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.