如何捕获整数(0)? [英] How to catch integer(0)?

查看:170
本文介绍了如何捕获整数(0)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个生成 integer(0)的语句,例如

  a<  -  which(1:3 == 5)

什么是最安全的抓取这个的方法?

解决方案

这是R打印零长度向量(整数一个)的方法,所以你可以测试对于 a 的长度为0:

  R>长度(a)
[1] 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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆