【发布时间】:2016-05-06 21:21:23
【问题描述】:
我正在尝试根据行标签或名称计算相对丰度(获取 df$path1 中每个测试的相对丰度。所以我想计算来自 test1 的计数的相对丰度,并计算相对丰度分别来自test2 的计数丰度。来自test1 的相对丰度数之和等于1。
我目前正在使用vegan 包,但可以使用其他选项。
测试数据集:
library(vegan)
df <- data.frame(x = c("a", "b", "c", "d", "e"),
path1 = c("test1", "test1", "test2", "test2", "test3"),
value = c(40, 10, 34, 12, 20))
df$relabun <- decostand(df[3], 2, method = "total") #takes relative abundace of whole column
基于df$path1 的相对丰度的理想输出如下所示:
x path1 relabun_bypath1
a test1 0.8
b test1 0.2
c test2 0.74
d test2 0.26
e test3 1
【问题讨论】: