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

前端 未结 3 612
无人及你
无人及你 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:15

    According to the help file ?`==`:

    If the two arguments are atomic vectors of different types, one is coerced to the type of the other, the (decreasing) order of precedence being character, complex, numeric, integer, logical and raw.

    So TRUE is coerced to "TRUE" (i. e. as.character(TRUE)), hence the equality.

    The equivalent of operator === (i. e. are the two objects equal and of the same type) would be function identical:

    identical(TRUE, "TRUE")
    [1] FALSE
    

提交回复
热议问题