涉及 NA 的逻辑运算
Logical operations involving NA
因为“is.na(NA)”returns true 和“NA > 0”returns NA,“is.na(NA) & (NA > 0)" 应该 return 并且这是真的。
is.na(NA) & NA >0
[1] NA
同理,"!is.na(NA)" returns为假,"NA > 0" returns NA, "!is.na ( NA) & (NA > 0)" 也应该 return NA。但是 Rreturn 是错误的。这是为什么?
!is.na(NA) & NA >0
[1] 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.
在 OP 的条件下,第一个评估为
TRUE & NA #(is.na(NA)#[1] TRUE;NA > 0#[1] NA)
第二个是
FALSE & NA #(!is.na(NA)#[1] FALSE)
因为“is.na(NA)”returns true 和“NA > 0”returns NA,“is.na(NA) & (NA > 0)" 应该 return 并且这是真的。
is.na(NA) & NA >0
[1] NA
同理,"!is.na(NA)" returns为假,"NA > 0" returns NA, "!is.na ( NA) & (NA > 0)" 也应该 return NA。但是 Rreturn 是错误的。这是为什么?
!is.na(NA) & NA >0
[1] 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.
在 OP 的条件下,第一个评估为
TRUE & NA #(is.na(NA)#[1] TRUE;NA > 0#[1] NA)
第二个是
FALSE & NA #(!is.na(NA)#[1] FALSE)