查找数字列表之间的值

时间:2018-09-04 00:56:17

标签: r subset

我有两个数字列表,如下所示。

x <- c(1, 5, 10, 17, 21, 30)
y <- c(2, 7, 19)

在我的数据集中,x将1到30划分为不同的段(从1-5、5-10、10-17、17-21、21-30)。是否可以将这些段与y中的数字进行匹配? (在这种情况下,我想获取c(1,5,17)作为输出,因为2在1和5之间,7在5和10之间,而19在17和21之间。)

3 个答案:

答案 0 :(得分:2)

=PERSONAL.XLSB!myFunctionName(A1) 进行救援:

?findInterval

答案 1 :(得分:2)

使用{% for app in applications %} {% if applicant.username in app.user.username %} #drawback of this code the loop runs even after the condition is met. No way in Django template to stop that. See my 2nd answer the code is better but logic run in views <p> Do A </p> {% endif %} {% empty %} <p> Do B <p> {% endfor %} 是另一种选择

cut

也可以使用cut(y, breaks = x, labels = x[-length(x)]) #[1] 1 5 17

labels = FALSE

答案 2 :(得分:0)

您可以使用@asynccontextmanager async def run_in_background(coro): task = asyncio.create_task(coro) yield task await task async def main(): async with run_in_background(long_task()): await short_task() 和一个简单的函数来完成此操作

sapply