Behavior of summing !is.na() results

后端 未结 1 1477
不知归路
不知归路 2020-12-10 13:11

Why does the first line return TRUE, and the third line returns 1? I would expect both lines to return 1. What is the exact meaning of those extra two parentheses in the thi

相关标签:
1条回答
  • 2020-12-10 13:50

    ! has a weird, counter-intuitive precedence in R.

    Your first code is equivalent to

    !(is.na(5) + !is.na(NA))
    

    That is, ! has lower precedence than +.

    0 讨论(0)
提交回复
热议问题