get common sampling sites from two data sets
Etienne Lalibert? wrote:
Here's one way. # create matrices x and y with some sites in common x <- matrix(1, 4, 2) ; rownames(x) <- letters[1:4] y <- matrix(1, 4, 2) ; rownames(y) <- letters[3:6] # identify which sites are in common for x and y xcommon <- rownames(x) %in% rownames(y) ycommon <- rownames(y) %in% rownames(x)
## you can also use the intersect function (does the same thing) common_sites<-intersect(rownames(y),rownames(x))
# create new x and y matrices with only sites shared x2 <- x[xcommon, ] y2 <- y[ycommon, ] Cheers Etienne 2011/3/17 Scott Chamberlain <scttchamberlain4 at gmail.com>
If your datasets are dataframes (or you could convet matrices to
dataframes), you can use
merge(x, y, by = "site")
if y sites are a subset of x that will work, but if there are some sites in
y that are not in x, then I think you would write
merge(x, y, by = "site", all = TRUE)
which will keep sites in y that are not in x, then you could just delete
sites not in x but in y
On Thursday, March 17, 2011 at 8:17 AM, Andres Mellado Diaz wrote:
Dear list members,
I have two data sets (sites by species) with some sites in common, one
with invertebrate data (X) and one with diatoms data (Y). I would like to
get both new Xc and Yc matrices showing only those sites common to X and Y,
to make similarity matrices and perform a mantel test. Hope you can help me
with this,
Many thanks in advance, Andr?s Dr. Andr?s Mellado D?az Center for Hydrological Studies CEH-CEDEX Water Quality Department P? bajo de la Virgen del Puerto, 3 28005, Madrid SPAIN [[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
[[alternative HTML version deleted]] ------------------------------------------------------------------------
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology