[英]How to conditionally identify identical & distinct species observations within a column
我正在尝试确定地上和地下采样地块之间哪些物种观察结果相同和不同。 我基本上是在寻找将 go 放入维恩图中的数据
下面是一些示例数据。 我正在寻找 2013 年地上和地下之间哪些物种相同(RUBUS 和 VITIS 在地上和地下之间共享)然后哪些物种不共享(2013 年地上的 ACTA 和 ARTR;2013 年地下的 BOCY 和 VIOLA)。 因此,有条件地识别列中不同和相同的观察结果。
Year <- c(2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013)
Layer <- c(aboveground, aboveground, aboveground, aboveground, belowground, belowground, belowground, belowground)
Species <- c(ACTA, ARTR, RUBUS, VITIS, BOCY, RUBUS, VIOLA, VITIS)
df <- c(Year, Layer, Species)
df %>% unique(Layer = Species) #Shot in the dark solution as I feel like the answer is going to be quite simple
我认为过滤或 ifelse function 都可以,但到目前为止我没有运气。 R 中的几个维恩图函数很笨拙,没有给出变量之间实际相似的观察结果
attr(gplots::venn(as.list(unstack(df, Species~Layer)),show.plot = FALSE), 'intersections')
$aboveground
[1] "ACTA" "ARTR"
$belowground
[1] "BOCY" "VIOLA"
$`aboveground:belowground`
[1] "RUBUS" "VITIS"
在哪里
df <- structure(list(Year = c(2013, 2013, 2013, 2013, 2013, 2013, 2013,
2013), Layer = c("aboveground", "aboveground", "aboveground",
"aboveground", "belowground", "belowground", "belowground", "belowground"
), Species = c("ACTA", "ARTR", "RUBUS", "VITIS", "BOCY", "RUBUS",
"VIOLA", "VITIS")), class = "data.frame", row.names = c(NA, -8L
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.