推荐答案使用dplyr:getValue <- function(x, data) { tmp <- data %>% filter(V2 <= x, x <= V3) return(tmp$V4)}x <- c(107599440, 150769180, 155204690)sapply(x, getValue, data=df)哪个返回:[1] "PRMT6" "CTSK" "GBA"注意:我已将您的数据复制到具有列名称V1,V2,V3和V4的数据框df中. V2和V3列是该范围的下限值和上限值.Note: I copied your data into a dataframe df that has column names V1, V2, V3, and V4. The columns V2 and V3 are the lower and upper values of the range.df <- read.table(text="chr1 100088228 100162167 AGLchr1 107599438 107600565 PRMT6chr1 115215635 115238091 AMPD1chr1 11850637 11863073 MTHFRchr1 119958143 119965343 HSD3B2chr1 144124628 144128902 HFE2chr1 150769175 150779181 CTSKchr1 154245300 154248277 HAX1chr1 155204686 155210803 GBAchr1 156084810 156108997 LMNA", stringsAsFactors=FALSE) 更新:如果有多个匹配项,则将返回第一个匹配项:In case of multiple matches, this will return the first match:getValue <- function(x, data) { tmp <- data %>% filter(V2 <= x, x <= V3) %>% filter(row_number() == 1) return(tmp$V4)}有多个排名功能.查看?row_number了解更多信息.There are multiple ranking functions. Check out ?row_number for more info. 这篇关于检查向量中的值是否在不同长度向量中的值范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-05 04:25