Skip to content
Prev 31152 / 398506 Next

matrix to coordinates

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