The difference between & and && in R

后端 未结 3 1894
鱼传尺愫
鱼传尺愫 2020-12-11 19:56

I have read

http://stat.ethz.ch/R-manual/R-devel/library/base/html/Logic.html

and the difference between & and && doesn\'t make sense. For examp

3条回答
  •  感情败类
    2020-12-11 20:12

    & is a logical operator so R coverts your quantities to logical values before comparison. For numeric values any non-0 (and non-NA/Null/NaN stuff) gets the value TRUE and 0 gets FALSE. So with that said things make quite a bit of sense

    > as.logical(c(1,2,3))
    [1] TRUE TRUE TRUE
    > as.logical(c(1,3,3))
    [1] TRUE TRUE TRUE
    > as.logical(c(1,2,3)) & as.logical(c(1,2,3))
    [1] TRUE TRUE TRUE
    > as.logical(c(1,2,3)) & as.logical(c(1,3,3))
    [1] TRUE TRUE TRUE
    

提交回复
热议问题