如何捕捉整数(0)? [英] How to catch integer(0)?
本文介绍了如何捕捉整数(0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我们有一个产生 integer(0)
的语句,例如
Let's say we have a statement that produces integer(0)
, e.g.
a <- which(1:3 == 5)
捕捉这个最安全的方法是什么?
What is the safest way of catching this?
推荐答案
这是 R 打印零长度向量(整数 1)的方式,因此您可以测试 a
的长度是否为 0:
That is R's way of printing a zero length vector (an integer one), so you could test for a
being of length 0:
R> length(a)
[1] 0
可能值得重新考虑您用于确定哪些元素所需的策略,但如果没有进一步的具体细节,则很难提出替代策略.
It might be worth rethinking the strategy you are using to identify which elements you want, but without further specific details it is difficult to suggest an alternative strategy.
这篇关于如何捕捉整数(0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文