提问人:LuleSa 提问时间:3/4/2023 更新时间:3/4/2023 访问量:28
函数 which() 和 match() 不适用于降序序列
functions which() and match() do not work on descending sequences
问:
我遇到了一件我无法解释的奇怪事情:
我正在尝试从另一个向量中的一个向量中查找元素的索引,我可以用 or 来做到这一点:which()
match()
test = seq(.1, 10, .1)
match(c(0.1, 0.2, 4, 7), test)
[1] 1 2 40 70
which(test %in% c(0.1, 0.2, 4, 7))
[1] 1 2 40 70
这是有道理的,但如果我颠倒顺序:
test = seq(10, .1, -.1)
match(c(0.1, 0.2, 4, 7), test)
[1] 100 NA 61 31
which(test %in% c(0.1, 0.2, 4, 7))
[1] 31 61 100
它找不到 .我最初的猜测是格式不正确,但它也找不到或0.2
0.200
test[99]
有人可以解释一下这里发生了什么吗?
答: 暂无答案
评论
seq(.1, 10, .1) == rev(seq(10, .1, -.1))