Why TRUE == “TRUE” is TRUE in R?

前端 未结 3 621
无人及你
无人及你 2020-11-29 05:29
  1. Why TRUE == \"TRUE\" is TRUE in R?
  2. Is there any equivalent for === in R?

Update:

<
3条回答
  •  伪装坚强ぢ
    2020-11-29 06:10

    In addition to

    TRUE == "TRUE"

    these are also true:

    • TRUE==1
    • TRUE==1.0
    • TRUE==1.0000000000000001
    • TRUE==0.99999999999999999 etc, in general also all values close enough to 1.0 to be IEEE754-rounded to it.

    But what is more interesing is what if() checks: it checks non-false; in fact this plots!:

    if(4.0) plot(1) 
    

    I think the only values that dont trigger if() are 0, F, FALSE and "FALSE" they seem defined as exactly 0.

提交回复
热议问题