簡體   English   中英

如何有條件地識別列中相同和不同的物種觀察結果

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM