How logical negation operator “!” works

后端 未结 3 1198
孤独总比滥情好
孤独总比滥情好 2021-01-11 15:20

I am not trying to solve any particular problem, but trying to learn R and understand its logical negation operator \"!\" documented on page http://stat.ethz.ch/R-manual/R-d

3条回答
  •  生来不讨喜
    2021-01-11 15:52

    I agree with everything said by the other two posters, but want to add one more thing I always tell when teaching R.

    R works in that it evaluates statements from the inside to the outside and each of those statements needs to run on it's own. If you already have an error in an inner statement, no wonder the outers do not produce anything.

    In your case one could say you have two statements: !x and list accessing on list via [.

    If you replicate R's behavior you notice that !x already produces the error:

    > !x
    Error in !x : invalid argument type
    

    Hence, the correct solutions try to change this step.

    So: Always check your innermost statements when an errors occurs and work yourself outwards.

提交回复
热议问题