df to link table

df2link(test, fun = sum)

Arguments

test

df with at least 3 columns

fun

function to summary the elements number, defalut: sum, you can choose mean.

Value

data.frame

Examples

data(otutab)
cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test
df2link(test)
#> $links
#>                            from                           to weight
#> 1                   k__Bacteria            p__Actinobacteria  54986
#> 2                   k__Bacteria             p__Bacteroidetes  16484
#> 3                   k__Bacteria            p__Proteobacteria  74430
#> 4             p__Actinobacteria            c__Actinobacteria  54986
#> 5              p__Bacteroidetes            c__Flavobacteriia  16484
#> 6             p__Proteobacteria       c__Alphaproteobacteria   7789
#> 7             p__Proteobacteria        c__Betaproteobacteria  36154
#> 8             p__Proteobacteria       c__Gammaproteobacteria  30487
#> 9             c__Actinobacteria           o__Actinomycetales  54986
#> 10       c__Alphaproteobacteria               o__Rhizobiales   7789
#> 11        c__Betaproteobacteria           o__Burkholderiales  36154
#> 12            c__Flavobacteriia          o__Flavobacteriales  16484
#> 13       c__Gammaproteobacteria           o__Pseudomonadales  30487
#> 14           o__Actinomycetales        f__Micromonosporaceae   8518
#> 15           o__Actinomycetales        f__Pseudonocardiaceae   9508
#> 16           o__Actinomycetales         f__Streptomycetaceae  10813
#> 17           o__Actinomycetales       f__Thermomonosporaceae  26147
#> 18           o__Burkholderiales            f__Comamonadaceae  25217
#> 19           o__Burkholderiales     f__un_o__Burkholderiales  10937
#> 20          o__Flavobacteriales         f__Flavobacteriaceae  16484
#> 21           o__Pseudomonadales          f__Pseudomonadaceae  30487
#> 22               o__Rhizobiales              f__Rhizobiaceae   7789
#> 23            f__Comamonadaceae                 g__Pelomonas  25217
#> 24         f__Flavobacteriaceae            g__Flavobacterium  16484
#> 25        f__Micromonosporaceae              g__Actinoplanes   8518
#> 26          f__Pseudomonadaceae               g__Rhizobacter  30487
#> 27        f__Pseudonocardiaceae                   g__Lentzea   9508
#> 28              f__Rhizobiaceae                 g__Rhizobium   7789
#> 29         f__Streptomycetaceae              g__Streptomyces  10813
#> 30       f__Thermomonosporaceae g__un_f__Thermomonosporaceae  26147
#> 31     f__un_o__Burkholderiales     g__un_o__Burkholderiales  10937
#> 32              g__Actinoplanes        s__un_g__Actinoplanes   8518
#> 33            g__Flavobacterium     s__Flavobacterium_terrae  16484
#> 34                   g__Lentzea    s__Lentzea_flaviverrucosa   9508
#> 35                 g__Pelomonas        s__Pelomonas_puraquae  25217
#> 36               g__Rhizobacter     s__Rhizobacter_bergeniae  16592
#> 37               g__Rhizobacter         s__un_g__Rhizobacter  13895
#> 38                 g__Rhizobium           s__un_g__Rhizobium   7789
#> 39              g__Streptomyces        s__un_g__Streptomyces  10813
#> 40 g__un_f__Thermomonosporaceae s__un_f__Thermomonosporaceae  26147
#> 41     g__un_o__Burkholderiales     s__un_o__Burkholderiales  10937
#> 
#> $nodes
#>                            name   level weight
#> 1                   k__Bacteria Kingdom 145900
#> 2             p__Actinobacteria  Phylum  54986
#> 3              p__Bacteroidetes  Phylum  16484
#> 4             p__Proteobacteria  Phylum  74430
#> 5             c__Actinobacteria   Class  54986
#> 6        c__Alphaproteobacteria   Class   7789
#> 7         c__Betaproteobacteria   Class  36154
#> 8             c__Flavobacteriia   Class  16484
#> 9        c__Gammaproteobacteria   Class  30487
#> 10           o__Actinomycetales   Order  54986
#> 11           o__Burkholderiales   Order  36154
#> 12          o__Flavobacteriales   Order  16484
#> 13           o__Pseudomonadales   Order  30487
#> 14               o__Rhizobiales   Order   7789
#> 15            f__Comamonadaceae  Family  25217
#> 16         f__Flavobacteriaceae  Family  16484
#> 17        f__Micromonosporaceae  Family   8518
#> 18          f__Pseudomonadaceae  Family  30487
#> 19        f__Pseudonocardiaceae  Family   9508
#> 20              f__Rhizobiaceae  Family   7789
#> 21         f__Streptomycetaceae  Family  10813
#> 22       f__Thermomonosporaceae  Family  26147
#> 23     f__un_o__Burkholderiales  Family  10937
#> 24              g__Actinoplanes   Genus   8518
#> 25            g__Flavobacterium   Genus  16484
#> 26                   g__Lentzea   Genus   9508
#> 27                 g__Pelomonas   Genus  25217
#> 28               g__Rhizobacter   Genus  30487
#> 29                 g__Rhizobium   Genus   7789
#> 30              g__Streptomyces   Genus  10813
#> 31 g__un_f__Thermomonosporaceae   Genus  26147
#> 32     g__un_o__Burkholderiales   Genus  10937
#> 33     s__Flavobacterium_terrae Species  16484
#> 34    s__Lentzea_flaviverrucosa Species   9508
#> 35        s__Pelomonas_puraquae Species  25217
#> 36     s__Rhizobacter_bergeniae Species  16592
#> 37 s__un_f__Thermomonosporaceae Species  26147
#> 38        s__un_g__Actinoplanes Species   8518
#> 39         s__un_g__Rhizobacter Species  13895
#> 40           s__un_g__Rhizobium Species   7789
#> 41        s__un_g__Streptomyces Species  10813
#> 42     s__un_o__Burkholderiales Species  10937
#>