RE: [R] transform large matrix into list

From: Jim Brennan <>
Date: Wed 08 Jun 2005 - 00:00:38 EST

First it looks like in L you need a 3 in row 3 col 2. Anyway I think this is a non elegant way to do it without a loop that you can easily improve I imagine and should be faster than the loop. You will have to adjust the numbers to fit you matrix size etc.

R>mat<-matrix(sample(0:9,100,replace=T),50,2)#your M
R>result<-cbind(new,new2,new3)# your L


-----Original Message-----
[] On Behalf Of Stefan Mischke Sent: June 7, 2005 8:56 AM
Subject: [R] transform large matrix into list

Dear List

I need to transform a large matrix M with many NAs into a list L with one row for each non missing cell. Every row should contain the cell value in the first column, and its coordinates of the matrix in column 2 and 3.


	x1	x2
y1	1	2
y2	4	5
y3	7	8

v	x	y
1	1	1
4	1	2
7	1	2
2	2	1
5	2	2
8	2	3

I'm trying to do this with a loop, but since my matrix is quite large (around 10k^2) this just takes a very long time. There must be a more efficient and elegant way to do this. Any hints?

Stefan mailing list PLEASE do read the posting guide! mailing list PLEASE do read the posting guide! Received on Wed Jun 08 00:36:31 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:26 EST