检查 R 中的值是否 == 整数(0) [英] Check if value == integer(0) in R

查看:49
本文介绍了检查 R 中的值是否 == 整数(0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中使用 grep 函数来检查是否满足条件正则表达式.

I'm using the grep function in R to check if a conditional regular expression is met.

我所拥有的是:grep(expression, string) 其中一个例子可能是

What I have is this: grep(expression, string) where an example might be

   value=  grep("\\s[A-z]", "  ")
   value

哪个输出

整数(0)

我想要做的是检查是否 value == integer(0)

What I want to be able to do is check is if value == integer(0) and

返回 TRUE 如果 valueinteger(0)

返回 FALSE 如果 value 不是 integer(0)

return FALSE if value is not integer(0)

有没有办法在 R 中做到这一点?如果有其他选择,我对他们持开放态度.例如,grep 可能具有将结果输出为逻辑值的选项,

Is there a way to do this in R? If there are alternatives, I am open to them. For example, grep might have an option to output the result as a logical value,

TRUEFALSE,或

01 或相关的东西.

0 and 1 or something related.

推荐答案

您可以使用 identical,这是测试两个对象是否完全相等的安全可靠方法(来自文档):

You can use identical which is the safe and reliable way to test two objects for being exactly equal (from the docs):

value = integer(0)

identical(value, integer(0))
# [1] TRUE

<小时>

或者做以下检查:


Or do the following check:

is.integer(value) && length(value) == 0
# [1] TRUE

这篇关于检查 R 中的值是否 == 整数(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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