下面是一個示例,其中foverlaps(...)
似乎在查找不重疊的匹配項。任何人都可以幫助我理解我做錯了什麼嗎?在浮點間隔上使用Foverlaps發生意外的行爲[已解決]
this post中的問題似乎是在data.table包中使用foverlaps(...)
的絕好機會。以下數據集來自該文章。
dinosaurs <- structure(list(GENUS = structure(1:3, .Label = c("Abydosaurus", "Achelousaurus", "Acheroraptor"), class = "factor"), ma_max = c(109, 84.9, 70.6), ma_min = c(94.3, 70.6, 66.043), ma_mid = c(101.65, 77.75, 68.3215)), .Names = c("GENUS", "ma_max", "ma_min", "ma_mid"), class = "data.frame", row.names = c(NA, -3L))
stages <- structure(list(Stage = structure(c(13L, 19L, 17L, 21L, 1L, 4L, 6L, 8L, 16L, 14L, 20L, 7L, 23L, 12L, 5L, 3L, 2L, 10L, 22L, 11L, 18L, 9L, 15L), .Label = c("Aalenian", "Albian", "Aptian", "Bajocian", "Barremian", "Bathonian", "Berriasian", "Callovian", "Campanian", "Cenomanian", "Coniacian", "Hauterivian", "Hettangian", "Kimmeridgian", "Maastrichtian", "Oxfordian", "Pliensbachian", "Santonian", "Sinemurian", "Tithonian", "Toarcian", "Turonian", "Valanginian"), class = "factor"),ma_max = c(201.6, 197, 190, 183, 176, 172, 168, 165, 161, 156, 151, 145.5, 140, 136, 130, 125, 112, 99.6, 93.5, 89.3, 85.8, 83.5, 70.6), ma_min = c(197, 190, 183, 176, 172, 168, 165, 161, 156, 151, 145.5, 140, 136, 130, 125, 112, 99.6, 93.5, 89.3, 85.8, 83.5, 70.6, 66.5), ma_mid = c(199.3, 193.5, 186.5, 179.5, 174, 170, 166.5, 163, 158.5, 153.5, 148.25, 142.75, 138, 133, 127.5, 118.5, 105.8, 96.55, 91.4, 87.55, 84.65, 77.05, 68.05)), .Names = c("Stage", "ma_max", "ma_min", "ma_mid"), class = "data.frame", row.names = c(NA, -23L))
dinosaurs
# GENUS ma_max ma_min ma_mid
# 1 Abydosaurus 109.0 94.300 101.6500
# 2 Achelousaurus 84.9 70.600 77.7500
# 3 Acheroraptor 70.6 66.043 68.3215
head(stages)
# Stage ma_max ma_min ma_mid
# 1 Hettangian 201.6 197 199.3
# 2 Sinemurian 197.0 190 193.5
# 3 Pliensbachian 190.0 183 186.5
# 4 Toarcian 183.0 176 179.5
# 5 Aalenian 176.0 172 174.0
# 6 Bajocian 172.0 168 170.0
目標是找出存在於每個地質階段的恐龍屬的數量。
library(data.table) # 1.9.4
setDT(dinosaurs)[,ma_mid:=NULL]
setDT(stages)[,ma_mid:=NULL]
setkey(dinosaurs,ma_min,ma_max)
foverlaps(stages,dinosaurs,type="any",nomatch=0)
# GENUS ma_max ma_min Stage i.ma_max i.ma_min
# 1: Abydosaurus 109.0 94.300 Albian 112.0 99.6
# 2: Abydosaurus 109.0 94.300 Cenomanian 99.6 93.5
# 3: Achelousaurus 84.9 70.600 Coniacian 89.3 85.8
# 4: Achelousaurus 84.9 70.600 Santonian 85.8 83.5
# 5: Acheroraptor 70.6 66.043 Campanian 83.5 70.6
# 6: Achelousaurus 84.9 70.600 Campanian 83.5 70.6
# 7: Acheroraptor 70.6 66.043 Maastrichtian 70.6 66.5
# 8: Achelousaurus 84.9 70.600 Maastrichtian 70.6 66.5
這主要是正確的,但看看第3行這似乎斷言森諾曼階段,從85.8 89.3億年前,與重疊河神龍屬,從70.6住84.9萬年前。我錯過了什麼?
你能用'1.9.5'來試試嗎? 'devtools :: install_github(「Rdatatable/data.table」,build_vignettes = FALSE)''。 – Arun
我試過這個,但最終得到'ERROR:編譯包data.table'失敗' ...錯誤:命令失敗(1) 另外:警告消息: 包'GenomicRanges'不可用(對於R版本3.1.1) ' – jlhoward
另外,它看起來像別人做了同樣的事情(請參閱問題中的鏈接),並沒有得到這個問題。 – jlhoward