Re: [R-sig-eco] subsetting lower triangle distance matrix based on variable in another object

2013-07-30 Thread Jari Oksanen
Kendra,

Subset a matrix an convert to dist. You must subset both rows and columns in 
the same way, and therefore you must use subsetting index instead of a subset() 
function. Let k be a vector that is TRUE for selected items; 
as.dist(yoursymmetricmatrix[k, k]) is what you are looking for.

Cheers, Jari Oksanen
 alkuperäinen viesti 
Lähettäjä: Mitchell, Kendra
Lähetetty:  31.07.2013, 02:38
Vastaanottaja: "" 
Aihe: [R-sig-eco] subsetting lower triangle distance matrix based on variable 
in another object

I have a number of dissimilarity matrices built in another program that I'd 
like to subset then run NMS.

#read in distance matrix
b_bc03 <-data.matrix(read.table("bac_final.an.thetayc.0.03.lt.ave.dist", 
row.names=1, header=T, fill=TRUE))  # creates a 736x736 double matrix

#read in environmental variables
 bac_env<-read.csv("bac_samples.csv", row.names=1, header=T)  # 736 obs. of 6 
variables

#The only way that I've figured out how to subset a lt matrix is to convert to 
dist object first
bc_dist<-as.dist(b_bc03)  # dist[27048]
tx_dist<-subset(bc_dist, bac_env$zone=="TX") # numeric[54316]

Here is where it falls apart, the subset doesn't keep the labels, just the 
values so I can't convert it back to a distance matrix.  I've looked through 
ecodist but can't find anyway in that package to select only certain samples.

Help please?

thanks
Kendra



--
Kendra Maas Mitchell, Ph.D.
Post Doctoral Research Fellow
University of British Columbia
604-822-5646

[[alternative HTML version deleted]]

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] subsetting lower triangle distance matrix based on variable in another object

2013-07-30 Thread Mitchell, Kendra
I have a number of dissimilarity matrices built in another program that I'd 
like to subset then run NMS.

#read in distance matrix
b_bc03 <-data.matrix(read.table("bac_final.an.thetayc.0.03.lt.ave.dist", 
row.names=1, header=T, fill=TRUE))  # creates a 736x736 double matrix

#read in environmental variables
 bac_env<-read.csv("bac_samples.csv", row.names=1, header=T)  # 736 obs. of 6 
variables

#The only way that I've figured out how to subset a lt matrix is to convert to 
dist object first
bc_dist<-as.dist(b_bc03)  # dist[27048]
tx_dist<-subset(bc_dist, bac_env$zone=="TX") # numeric[54316]

Here is where it falls apart, the subset doesn't keep the labels, just the 
values so I can't convert it back to a distance matrix.  I've looked through 
ecodist but can't find anyway in that package to select only certain samples.

Help please?

thanks
Kendra



--
Kendra Maas Mitchell, Ph.D.
Post Doctoral Research Fellow
University of British Columbia
604-822-5646

[[alternative HTML version deleted]]

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology