I did not post this question to the ecology list, even though it is about an analysis using Vegan, since my question is based more on basic data manipulation in R.  I think this is a fairly simple question but for the life of me I cannot find a reference for in the archives.

I have an analysis using a matrix in which I needed to strip the ID variable off the input data to run the analysis.  Now I want to reattach the ID back to the results matrix but I can't seem to find a way to join the ID back.  Below is the exact input I'm using, row 9 is where I strip the Site_ID value from the input data.

library(vegan)
library(reshape)
csv_base <- read.csv("c:/temp/cvs_export.csv", header=T, as.is=T)
csv_basef <- subset(csv_base, Site_Id >= 1)
testm <- melt(csv_basef, id = 1:4, measure = 5)
test <- cast(testm, Site_Id ~ Element_Id, sum)
dim(test)
names(test)
csv.data <- test[,c(-1)]
csv.m <- as.matrix(csv.data,)
dimnames(csv.m) <- list(test$site_id, names(csv.data))
csv.dis <- vegdist(csv.m, "jaccard",binary="TRUE",diag="FALSE", upper="TRUE")
x <- as.matrix(csv.dis,)
triang <- x[row(x) > col(x)]
xt <- as.matrix(triang,)
condense <- cbind(row= as.vector(row(x)), col=as.vector(col(x)), value=as.vector(x))
write.csv(condense, "c:/temp/sim_out.csv", row.names = FALSE)

In my process I use the Site_ID, ElementId, and the Area variables (line 6). The 1st few lines of the input data are of the format:

Site_Id,Element_Name,Occurence_Identifier,Element_Id,Area,Cell_Count,Min_Condition,Avg_Conditon,Max_Condition,Summed_Conditon
0,Bosques y arbustales inundables,16,225,27,27,0.200000003,0.200000003,0.200000003,5.40000008
0,Bosques y arbustales inundables,17,225,6,6,0.200000003,0.200000003,0.200000003,1.200000018
1,Arbustales sabanas en piedemonte,83,187,85,85,0.400000006,0.400000006,0.400000006,34.00000051
1,Arbustales sabanas en lomerio quebrado,28,194,15,15,0.400000006,0.400000006,0.400000006,6.000000089
2,Arbustales sabanas en piedemonte,83,187,55,55,0.400000006,0.400000006,0.400000006,22.00000033
3,Arbustales sabanas en piedemonte,83,187,1,1,0.400000006,0.400000006,0.400000006,0.400000006
5,Arbustales sabanas en piedemonte,89,187,14,14,0.400000006,0.400000006,0.400000006,5.600000083

In my analysis I rotate the data to a matrix, and then complete the analysis w/o the Site_Id variable:

[1] "Site_Id" "187"     "190"     "194"     "203"     "211"     "213"
 [8] "215"     "217"     "219"     "221"     "225"     "227"     "230"
[15] "232"     "234"     "237"

My output table is pretty straight forward:

"row","col","value"
1,1,0
2,1,0.45
3,1,0.99
4,1,0.86
5,1,1
6,1,1
7,1,1
8,1,1
9,1,1
10,1,1
11,1,0.57
12,1,0.61

The issue is how to I put the actual Site_Id value back into my results?  In this case row 1, col 1 would be site 0, row 2, col 1 would be site 1, ... so on and so forth.

Thanks for any direction that might be offered.

-Jon

***********************************************************
John Hak
Senior GIS Analyst/Ecologist
NatureServe - A Network Connecting Science with Conservation
4001 Discovery Drive, Suite 2110
Boulder, CO 80303
(703) 797-4809
Skype: jon.hak
ü Please consider the environment before printing this e-mail




	[[alternative HTML version deleted]]

