I've just encounter a weird behaviour of R which I would like to understand.
When I do NA^0
it gives 1 and not NA as I would have expected.
example:
v1 <- c(2,NA,1)
v1^0
[1] 1 1 1
v1**0
[1] 1 1 1
^
and **
are arithmetic operators (help("^")
) like -
, +
, etc. which in their case gives NA:
v1+0
[1] 2 NA 1
v1-0
[1] 2 NA 1
Why are the different operators performe differently with NAs?