From an abundance matrix (numbers of individuals of a given species at a site) returns a relative abundance matrix (proportion of individuals of a given species at a given site). This function works also with sparse matrices.

make_relative(abund_matrix)

Arguments

abund_matrix

abundance matrix, with sites in rows and species in columns.

Value

Similar shaped matrix as the input but with relative abundances instead

Examples

data("aravo", package = "ade4")

# Site-species matrix
mat = as.matrix(aravo$spe)
head(mat)[, 1:5]  # Has absolute abundances
#>      Agro.rupe Alop.alpi Anth.nipp Heli.sede Aven.vers
#> AR07         0         0         0         0         0
#> AR71         0         0         0         0         0
#> AR26         3         0         1         0         1
#> AR54         0         0         0         2         0
#> AR60         0         0         0         0         0
#> AR70         0         0         0         0         0
rel_mat = make_relative(mat)
head(rel_mat)  # Relative abundances
#>       Agro.rupe Alop.alpi  Anth.nipp  Heli.sede  Aven.vers  Care.rosa Care.foet
#> AR07 0.00000000         0 0.00000000 0.00000000 0.00000000 0.06666667         0
#> AR71 0.00000000         0 0.00000000 0.00000000 0.00000000 0.08695652         0
#> AR26 0.08108108         0 0.02702703 0.00000000 0.02702703 0.05405405         0
#> AR54 0.00000000         0 0.00000000 0.08695652 0.00000000 0.08695652         0
#> AR60 0.00000000         0 0.00000000 0.00000000 0.00000000 0.00000000         0
#> AR70 0.00000000         0 0.00000000 0.00000000 0.00000000 0.09375000         0
#>       Care.parv Care.rupe  Care.semp Fest.laev  Fest.quad  Fest.viol  Kobr.myos
#> AR07 0.00000000   0.20000 0.00000000         0 0.13333333 0.00000000 0.06666667
#> AR71 0.04347826   0.00000 0.00000000         0 0.00000000 0.00000000 0.13043478
#> AR26 0.00000000   0.00000 0.02702703         0 0.08108108 0.02702703 0.10810811
#> AR54 0.00000000   0.00000 0.00000000         0 0.04347826 0.00000000 0.04347826
#> AR60 0.00000000   0.00000 0.00000000         0 0.23076923 0.07692308 0.07692308
#> AR70 0.03125000   0.03125 0.00000000         0 0.00000000 0.00000000 0.12500000
#>       Luzu.lute   Poa.alpi Poa.supi  Sesl.caer Alch.pent  Alch.glau Alch.vulg
#> AR07 0.00000000 0.06666667        0 0.00000000         0 0.00000000         0
#> AR71 0.00000000 0.08695652        0 0.00000000         0 0.00000000         0
#> AR26 0.02702703 0.00000000        0 0.00000000         0 0.02702703         0
#> AR54 0.00000000 0.08695652        0 0.04347826         0 0.00000000         0
#> AR60 0.00000000 0.00000000        0 0.07692308         0 0.00000000         0
#> AR70 0.00000000 0.06250000        0 0.03125000         0 0.00000000         0
#>      Andr.brig  Ante.carp Ante.dioi Arni.mont Aste.alpi  Bart.alpi  Camp.sche
#> AR07         0 0.00000000         0         0         0 0.00000000 0.00000000
#> AR71         0 0.04347826         0         0         0 0.04347826 0.04347826
#> AR26         0 0.02702703         0         0         0 0.00000000 0.02702703
#> AR54         0 0.00000000         0         0         0 0.00000000 0.04347826
#> AR60         0 0.00000000         0         0         0 0.00000000 0.07692308
#> AR70         0 0.03125000         0         0         0 0.03125000 0.03125000
#>      Card.alpi Cera.stri Cera.cera Leuc.alpi Cirs.acau  Drab.aizo  Drya.octo
#> AR07         0   0.00000         0         0         0 0.00000000 0.00000000
#> AR71         0   0.00000         0         0         0 0.00000000 0.04347826
#> AR26         0   0.00000         0         0         0 0.00000000 0.00000000
#> AR54         0   0.00000         0         0         0 0.04347826 0.00000000
#> AR60         0   0.00000         0         0         0 0.00000000 0.00000000
#> AR70         0   0.03125         0         0         0 0.00000000 0.03125000
#>       Erig.unif Gent.camp  Gent.acau  Gent.vern  Geum.mont Omal.supi  Andr.vita
#> AR07 0.00000000         0 0.00000000 0.00000000 0.00000000         0 0.00000000
#> AR71 0.00000000         0 0.00000000 0.00000000 0.00000000         0 0.00000000
#> AR26 0.02702703         0 0.02702703 0.02702703 0.05405405         0 0.00000000
#> AR54 0.04347826         0 0.00000000 0.04347826 0.00000000         0 0.00000000
#> AR60 0.00000000         0 0.00000000 0.07692308 0.00000000         0 0.07692308
#> AR70 0.00000000         0 0.00000000 0.00000000 0.00000000         0 0.00000000
#>      Hier.pili Homo.alpi Leon.pyre  Ligu.muto  Lloy.sero  Minu.sedo  Minu.vern
#> AR07         0   0.00000         0 0.00000000 0.00000000 0.06666667 0.06666667
#> AR71         0   0.00000         0 0.04347826 0.04347826 0.00000000 0.00000000
#> AR26         0   0.00000         0 0.00000000 0.00000000 0.00000000 0.02702703
#> AR54         0   0.00000         0 0.04347826 0.00000000 0.00000000 0.04347826
#> AR60         0   0.00000         0 0.00000000 0.00000000 0.00000000 0.07692308
#> AR70         0   0.03125         0 0.06250000 0.03125000 0.00000000 0.00000000
#>      Phyt.orbi Plan.alpi  Poly.vivi  Pote.aure  Pote.cran Pote.gran  Puls.vern
#> AR07         0         0 0.06666667 0.00000000 0.00000000         0 0.00000000
#> AR71         0         0 0.04347826 0.00000000 0.00000000         0 0.00000000
#> AR26         0         0 0.02702703 0.05405405 0.02702703         0 0.05405405
#> AR54         0         0 0.00000000 0.00000000 0.00000000         0 0.00000000
#> AR60         0         0 0.07692308 0.00000000 0.00000000         0 0.00000000
#> AR70         0         0 0.03125000 0.00000000 0.00000000         0 0.00000000
#>      Ranu.kuep Sagi.glab Sali.herb  Sali.reti  Sali.retu  Sali.serp  Saxi.pani
#> AR07         0         0         0 0.00000000 0.00000000 0.00000000 0.06666667
#> AR71         0         0         0 0.04347826 0.08695652 0.04347826 0.00000000
#> AR26         0         0         0 0.00000000 0.00000000 0.00000000 0.00000000
#> AR54         0         0         0 0.00000000 0.00000000 0.00000000 0.08695652
#> AR60         0         0         0 0.00000000 0.00000000 0.00000000 0.07692308
#> AR70         0         0         0 0.06250000 0.06250000 0.00000000 0.03125000
#>      Sedu.alpe  Semp.mont Sene.inca Sibb.proc  Sile.acau  Thym.poly Vero.alpi
#> AR07         0 0.00000000         0         0 0.06666667 0.00000000         0
#> AR71         0 0.04347826         0         0 0.04347826 0.00000000         0
#> AR26         0 0.02702703         0         0 0.02702703 0.00000000         0
#> AR54         0 0.04347826         0         0 0.00000000 0.08695652         0
#> AR60         0 0.00000000         0         0 0.00000000 0.00000000         0
#> AR70         0 0.03125000         0         0 0.06250000 0.00000000         0
#>      Vero.alli  Vero.bell  Myos.alpe Tara.alpi  Scab.luci  Anth.alpe  Oxyt.camp
#> AR07         0 0.00000000 0.00000000         0 0.00000000 0.00000000 0.06666667
#> AR71         0 0.00000000 0.00000000         0 0.00000000 0.04347826 0.00000000
#> AR26         0 0.00000000 0.02702703         0 0.02702703 0.00000000 0.02702703
#> AR54         0 0.04347826 0.04347826         0 0.00000000 0.00000000 0.00000000
#> AR60         0 0.00000000 0.00000000         0 0.00000000 0.00000000 0.00000000
#> AR70         0 0.03125000 0.00000000         0 0.00000000 0.00000000 0.00000000
#>       Oxyt.lapp Lotu.alpi Trif.alpi Trif.badi Trif.thal
#> AR07 0.06666667         0         0         0         0
#> AR71 0.04347826         0         0         0         0
#> AR26 0.00000000         0         0         0         0
#> AR54 0.04347826         0         0         0         0
#> AR60 0.07692308         0         0         0         0
#> AR70 0.03125000         0         0         0         0