我无法理解我错过了一些明显的东西.是否有更清晰或更惯用的方式来执行以下功能?
closest.preceding <- function(candidates, limit) {
# return the value in candidates that is closest to but less than the limit
return(limit - min(limit-candidates[candidates < limit]))
}
Run Code Online (Sandbox Code Playgroud)
感谢您的任何见解.
你可以这样做:
max(candidates[candidates<limit])
Run Code Online (Sandbox Code Playgroud)
哪个首先筛选出(严格地)小于限制的候选者,然后取出那些(最接近的)的最大值.
我相信还有其他方法.
| 归档时间: |
|
| 查看次数: |
5312 次 |
| 最近记录: |