0

I have a table of species combinations that overlap geographically.

Sp_a    Sp_b   prop_overlap
Cat     Dog    1

But I want to create a matrix that looks like this:

      Cat 
Dog    1

I have approximately 180000 combinations. Is there any quick way of converting this information in R?

I have tried:

    m <- matrix( NA, ncol = max(species_int$sp_a) , nrow = max(species_int$sp_b) ) 
m[ cbind( species_int$sp_b , species_int$sp_a ) ] <- species_int$prop_overlap 

Thanks

1 Answers1

0

Thanks, just had to rewrite it a little:

library(reshape2)
m <- acast(species_int, sp_a~sp_b, value.var = "prop_overlap")