For each sample in column variable I would like to add a new row named "Other" that should represent the fraction of ID/Phyla that are not part of the data frame, calculated as 100 minus the sum of value for each species.
tidyverse summarise_each is probably a way?
Desired out:
ID Phyla variable value
1 s__Streptococcus_lutetiensis p__Firmicutes Sample1 24.51658
2 s__Streptococcus_equinus p__Firmicutes Sample1 12.33968
3 s__Ligilactobacillus_animalis p__Firmicutes Sample1 10.00188
4 s__Prevotella_copri_clade_A p__Bacteroidetes Sample1 5.16247
5 s__Catenibacterium_sp_AM22_15 p__Firmicutes Sample1 4.56347
Other Other Sample1 43.41592
6 s__GGB6572_SGB9285 p__Proteobacteria Sample2 34.40184
7 s__Blautia_producta p__Firmicutes Sample2 20.38267
8 s__GGB2738_SGB3684 p__Proteobacteria Sample2 18.77016
9 s__Amedibacterium_intestinale p__Firmicutes Sample2 9.94069
10 s__GGB48468_SGB66515 p__Bacteroidetes Sample2 4.14584
Other Other Sample2 12.3588
In:
ID Phyla variable value
1 s__Streptococcus_lutetiensis p__Firmicutes Sample1 24.51658
2 s__Streptococcus_equinus p__Firmicutes Sample1 12.33968
3 s__Ligilactobacillus_animalis p__Firmicutes Sample1 10.00188
4 s__Prevotella_copri_clade_A p__Bacteroidetes Sample1 5.16247
5 s__Catenibacterium_sp_AM22_15 p__Firmicutes Sample1 4.56347
6 s__GGB6572_SGB9285 p__Proteobacteria Sample2 34.40184
7 s__Blautia_producta p__Firmicutes Sample2 20.38267
8 s__GGB2738_SGB3684 p__Proteobacteria Sample2 18.77016
9 s__Amedibacterium_intestinale p__Firmicutes Sample2 9.94069
10 s__GGB48468_SGB66515 p__Bacteroidetes Sample2 4.14584
In dput:
structure(list(ID = c("s__Streptococcus_lutetiensis", "s__Streptococcus_equinus",
"s__Ligilactobacillus_animalis", "s__Prevotella_copri_clade_A",
"s__Catenibacterium_sp_AM22_15", "s__GGB6572_SGB9285", "s__Blautia_producta",
"s__GGB2738_SGB3684", "s__Amedibacterium_intestinale", "s__GGB48468_SGB66515"
), Phyla = c("p__Firmicutes", "p__Firmicutes", "p__Firmicutes",
"p__Bacteroidetes", "p__Firmicutes", "p__Proteobacteria", "p__Firmicutes",
"p__Proteobacteria", "p__Firmicutes", "p__Bacteroidetes"), variable = c("Sample1",
"Sample1", "Sample1", "Sample1", "Sample1", "Sample2", "Sample2",
"Sample2", "Sample2", "Sample2"), value = c(24.51658, 12.33968,
10.00188, 5.16247, 4.56347, 34.40184, 20.38267, 18.77016, 9.94069,
4.14584)), row.names = c(NA, -10L), class = "data.frame")