我正在尝试基于物种的普遍性进行分类,共有4个分类:
我尝试过类似于这样的方法:
- 稀有 - 频率<均值 & 相对丰度<均值
- 偶发 - 频率<均值 & 相对丰度>均值
- 常见 - 频率>均值 & 相对丰度<均值
- 优势 - 频率>均值 & 相对丰度>均值
species <- c("a", "b", "c", "d", "e", "f")
relabund <- c(.5, .11, .23, .06, .36, .19) #relative abundance
freq <- c(6, 3, 20, 2, 11, 4) #number of sites species occurs at
df = data.frame(species, relabund, freq)
我尝试过类似于这样的方法:
if (df[,2]>mean(relabund) && df[,3]>mean(freq)) {
df$Classification = "Dominant"
} else if (df[,2]<mean(relabund) && df[,3]<mean(freq)) {
df$Classification = "Rare"
} else if (df[,2]<mean(relabund) && df[,3]>mean(freq)) {
df$Classification = "Common"
} else
df$Classification = "Occasional"
但是这样做并不起作用,因为它会将所有物种都分类为“Rare”。我非常新手 if else 语句,所以任何帮助将不胜感激。
谢谢!