Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.SOL.4.44.0304241403270.26646-100000@rygar.gpcc.itd.umich.edu>
Date: 2003-04-24T18:06:26Z
From: Thomas W Blackwell
Subject: matrix to coordinates
In-Reply-To: <3EA8104F.1020905@ceam.es>

The two functions  row(), col()  are useful here:

aa <- data.frame(r=as.vector(row(m)), c=as.vector(col(m)), v=as.vector(m))

There's no other ready-made function for this, AFAIK.

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Thu, 24 Apr 2003, juli g. pausas wrote:

> Dear R-users,
> I'm sure it must be a specific function or a better way to convert
> matrix to x,y,z coordinates (and viceversa), than my function below (it
> works). Any help?
>
> m2coord <- function(m)
> {
> k <- nrow(m)*ncol(m)
> aa <- data.frame(r=1:k, c=1:k, v=1:k)
> k <- 0
>   for (i in 1:nrow(m))
>   for (j in 1:ncol(m))
>   {
>   k <- k+1
>   aa$f[k]=i; aa$c[k]=j; aa$v[k]=m[i,j]
>   }
> aa
> }
>
> Juli
> --
> Juli G. Pausas
> Centro de Estudios Ambientales del Mediterraneo (CEAM)
> C/ C.R. Darwin 14, Parc Tecnologic,
> 46980 Paterna, Valencia, SPAIN
> Tel: (+ 34) 96 131 8227; Fax: (+ 34) 96 131 8190
> mailto:juli at ceam.es
> http://www.gva.es/ceam