Find which interval row in a data frame that each element of a vector belongs in

后端 未结 7 682
一整个雨季
一整个雨季 2020-11-29 06:29

I have a vector of numeric elements, and a dataframe with two columns that define the start and end points of intervals. Each row in the dataframe is one interval. I want to

相关标签:
7条回答
  • 2020-11-29 07:02

    cut is possibly useful here.

    out <- cut(elements, t(intervals[c("start","end")]))
    levels(out)[c(FALSE,TRUE)]  <- NA
    intervals$phase[out]
    #[1] "a" "a" "a" NA  "b" "b" "c"
    
    0 讨论(0)
提交回复
热议问题