Created
March 25, 2013 16:37
-
-
Save pedroj/5238527 to your computer and use it in GitHub Desktop.
pairwise vectorization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################### | |
# Getting the pairwise interactions list | |
# Format: "Pant.species-Animal.species" | |
# assocs is a matrix (AxP). With rownames and colnames. | |
# | |
# pairwise(t(assocs)) will give the interactions list | |
# as: "Animal.species-Pant.species" | |
# Pedro Jordano. Sevilla - 15 Abr 2006 02:13:45. | |
#-------------------------------------------------------- | |
pairwise<-function(assocs) { | |
A <- as.matrix(as.vector(as.matrix(assocs))) | |
data.vecs <- A | |
nassocs <- length(A) | |
nspp1 <- dim(assocs)[1] | |
nspp2 <- dim(assocs)[2] | |
sppnames1 <- rownames(assocs) | |
sppnames2 <- colnames(assocs) | |
pairnames = NULL | |
for (o in 1:(nspp2)) { | |
for (u in 1:nspp1) { | |
pairnames <- c(pairnames, paste(sppnames2[o], | |
sppnames1[u], sep = "-")) | |
} | |
} | |
pairnames | |
} | |
######################################################### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment