I have read everything I can find on how to manipulate a results matrix in R and I have to admit I'm stumped. I have set up a process to extract a dataset from ArcGIS to compute a similarity index (Jaccards) in Vegan. The dataset is fairly simple, but large, and consists of rows = sample area, and columns = elements. I've been able to view the results in R, but I want to get the results out to a database and a matrix that is 6000-rows x 6000-columns can be very difficult to manipulate in Windows XP. I would to rotate the matrix so that the output would look like the old condensed format in programs like Conoco. Ideally, I would like format to look something like this; Site-row Site-col Jaccard 1 1 1 1 2 .9 1 3 .6 2 1 .9 2 2 1 2 3 .75 Thanks for any help, *********************************************************** John Hak Senior GIS Analyst/Sr. Ecologist NatureServe 4001 Discovery Drive Boulder, CO 80303 (703) 797-4809 There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world. To me, it underscores our responsibility to deal more kindly with one another, and to preserve and cherish the pale blue dot, the only home we've ever known. --Carl Sagan ?
Is this what you want?> x[,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25> cbind(row=as.vector(row(x)), col=as.vector(col(x)), value=as.vector(x))row col value [1,] 1 1 1 [2,] 2 1 2 [3,] 3 1 3 [4,] 4 1 4 [5,] 5 1 5 [6,] 1 2 6 [7,] 2 2 7 [8,] 3 2 8 [9,] 4 2 9 [10,] 5 2 10 [11,] 1 3 11 [12,] 2 3 12 [13,] 3 3 13 [14,] 4 3 14 [15,] 5 3 15 [16,] 1 4 16 [17,] 2 4 17 [18,] 3 4 18 [19,] 4 4 19 [20,] 5 4 20 [21,] 1 5 21 [22,] 2 5 22 [23,] 3 5 23 [24,] 4 5 24 [25,] 5 5 25>On 6/25/07, Jon Hak <Jon_Hak@natureserve.org> wrote:> > I have read everything I can find on how to manipulate a results matrix in > R and I have to admit I'm stumped. I have set up a process to extract a > dataset from ArcGIS to compute a similarity index (Jaccards) in Vegan. The > dataset is fairly simple, but large, and consists of rows = sample area, and > columns = elements. I've been able to view the results in R, but I want to > get the results out to a database and a matrix that is 6000-rows x > 6000-columns can be very difficult to manipulate in Windows XP. I would to > rotate the matrix so that the output would look like the old condensed > format in programs like Conoco. Ideally, I would like format to look > something like this; > > > Site-row Site-col Jaccard > 1 1 1 > 1 2 .9 > 1 3 .6 > 2 1 .9 > 2 2 1 > 2 3 .75 > > Thanks for any help, > > > > > *********************************************************** > John Hak > Senior GIS Analyst/Sr. Ecologist > NatureServe > 4001 Discovery Drive > Boulder, CO 80303 > (703) 797-4809 > > There is perhaps no better demonstration of the folly of human conceits > than this distant image of our tiny world. To me, it underscores our > responsibility to deal more kindly with one another, and to preserve and > cherish the pale blue dot, the only home we've ever known. --Carl Sagan > > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
On Mon, 2007-06-25 at 10:58 -0400, Jon Hak wrote:> I have read everything I can find on how to manipulate a results > matrix in R and I have to admit I'm stumped. I have set up a process > to extract a dataset from ArcGIS to compute a similarity index > (Jaccards) in Vegan. The dataset is fairly simple, but large, and > consists of rows = sample area, and columns = elements. I've been > able to view the results in R, but I want to get the results out to a > database and a matrix that is 6000-rows x 6000-columns can be very > difficult to manipulate in Windows XP. I would to rotate the matrix > so that the output would look like the old condensed format in > programs like Conoco. Ideally, I would like format to look something > like this; > > > Site-row Site-col Jaccard > 1 1 1 > 1 2 .9 > 1 3 .6 > 2 1 .9 > 2 2 1 > 2 3 .75 > > Thanks for any help,Presuming that your source matrix for the above is: mat <- matrix(c(1, .9, .6, .9, 1, .75), ncol = 3, byrow = TRUE)> mat[,1] [,2] [,3] [1,] 1.0 0.9 0.60 [2,] 0.9 1.0 0.75 You can use the following: t.mat <- t(mat) Res <- cbind("Site-row" = as.vector(col(t.mat)), "Site-col" = as.vector(row(t.mat)), Jaccard = as.vector(t.mat))> ResSite-row Site-col Jaccard [1,] 1 1 1.00 [2,] 1 2 0.90 [3,] 1 3 0.60 [4,] 2 1 0.90 [5,] 2 2 1.00 [6,] 2 3 0.75 See ?t and ?row HTH, Marc Schwartz