簡體   English   中英

如何在 r 或 python 中找到並突出顯示彼此一定范圍內的值簇?

[英]How can I find and highlight clusters of values within a certain range of each other in r or python?

我有一個數字列表(都大於 10,000,000) ,我想找到彼此相差5,000,000以內的數字簇(這些數字對應於曼哈頓圖中基因 SNP 突變的列)。

有沒有辦法對列表進行聚類分析,以便我可以編寫一個文件,其中: If [i]+1 < [i]+5,000,000

它會突出顯示文件中的那些值嗎? 我現在將它作為 excel 文件,但可以更改格式。 謝謝。

你會在這里得到幾個可能的答案。 我喜歡data.table包,因為它速度很快並且有很多有用的內置操作符。 在這種情況下,我們可以使用shift()參數來比較觀察i和觀察i + 1 您可以將其分解為多個步驟,但將所有邏輯合並為一行如下所示:

library(data.table)

set.seed(1)
dt <- data.table(int = sample(10000000:100000000, 10000, replace = TRUE))

dt[, highlight := ifelse(shift(int,n = 1, type = "lead") < int + 5000000, "highlight", "no highlight")]
#show how many rows fit our criteria defined above
table(dt$highlight)
#> 
#>    highlight no highlight 
#>         5524         4475

reprex 包(v0.2.1) 於 2019 年 1 月 24 日創建

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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