Find nearest smaller number

前端 未结 7 1297
粉色の甜心
粉色の甜心 2021-01-18 12:35

I have a vector of numbers

f <- c(1, 3, 5, 8, 10, 12, 19, 27)

I want to compare the values in the vector to another number, and find the c

7条回答
  •  無奈伤痛
    2021-01-18 12:38

    In a functional programming style:

    f <- c(1, 3, 6, 8, 10, 12, 19, 27)
    x <- 18
    Position(function(fi) fi <= x, f, right = TRUE)
    

提交回复
热议问题