looking for some solutions? You are welcome.

SOLVED: Summarising a table as a matrix

LizzyJ:

I have a dataframe of which areas certain species occur in, where 1 = present, and 0 = absent. I would like to create a pairwise matrix summing the number of species with shared areas. This is an example of my data:

My data:

structure(c(0.5, 0.3, 0.25, 0.5, 0.3, 0.25, 0, 0.3, 0.25, 0, 0, 0.25), .Dim = 3:4, 
          .Dimnames = list(c("Species1", "Species2", "Species3"), 
                           c("AreaA", "AreaB", "AreaC", "AreaD")))

         AreaA AreaB AreaC AreaD
Species1  0.5   0.5   0     0
Species2  0.3   0.3   0.3   0
Species3  0.25  0.25  0.25  0.25

And I would like something like this in the end:

      AreaA AreaB AreaC AreaD
AreaA     0   2.1   1.1   0.5
AreaB         0     1.1   0.5
AreaC               0     0.5
AreaD                     0

I have a list of over 50,000 species I need to summarise shared areas for.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent