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

JeeBee JeeBee at troefpunt.nl
Tue Aug 1 16:52:21 CEST 2006


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)) )

JeeBee.



More information about the R-help mailing list