具有NA,TRUE和FALSE的逻辑运算符(AND,OR) [英] Logical operators (AND, OR) with NA, TRUE and FALSE

查看:457
本文介绍了具有NA,TRUE和FALSE的逻辑运算符(AND,OR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当与逻辑OR(|)和逻辑AND(&)一起使用时,我无法理解逻辑(布尔)值TRUEFALSENA的属性.以下是一些示例:

I cannot understand the properties of logical (boolean) values TRUE, FALSE and NA when used with logical OR (|) and logical AND (&). Here are some examples:

NA | TRUE
# [1] TRUE

NA | FALSE
# [1] NA

NA & TRUE
# [1] NA

NA & FALSE
# [1] FALSE

您能解释这些输出吗?

推荐答案

引用?Logic:

NA是有效的逻辑对象.如果x或y的分量为NA,则 如果结果不明确,则结果为NA.换句话说,NA&N. TRUE表示NA,但NA& FALSE评估为FALSE.见 下面的示例.

NA is a valid logical object. Where a component of x or y is NA, the result will be NA if the outcome is ambiguous. In other words NA & TRUE evaluates to NA, but NA & FALSE evaluates to FALSE. See the examples below.

其中的关键是模糊"一词. NA表示未知".因此NA & TRUE可以为true或false,但我们不知道.而NA & FALSE将为假,无论缺失值是什么.

The key there is the word "ambiguous". NA represents something that is "unknown". So NA & TRUE could be either true or false, but we don't know. Whereas NA & FALSE will be false no matter what the missing value is.

这篇关于具有NA,TRUE和FALSE的逻辑运算符(AND,OR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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