美文网首页
& vs && in R

& vs && in R

作者: 为了梦走一遭 | 来源:发表于2021-11-12 06:09 被阅读0次

Copy from: https://stackoverflow.com/questions/6558921/boolean-operators-and

The shorter ones are vectorized, meaning they can return a vector, like this:

((-2:2) >= 0) & ((-2:2) <= 0)

[1] FALSE FALSE TRUE FALSE FALSE

The longer form evaluates left to right examining only the first element of each vector, so the above gives

((-2:2) >= 0) && ((-2:2) <= 0)

[1] FALSE

As the help page says, this makes the longer form "appropriate for programming control-flow and [is] typically preferred in if clauses."

相关文章

网友评论

      本文标题:& vs && in R

      本文链接:https://www.haomeiwen.com/subject/rxenzltx.html