4 ms·
1^NA is 1, and 2^NA is NA. Bizarre!
by nomilk 5y ago
1^NA is 1, and 2^NA is NA. Bizarre!
- fithisux 5y agoR has many cases of inconsistency. Like substitute "its value is substituted, unless env is .GlobalEnv in which case the symbol is left unchanged." dim and dims :-) R could do more here. I really like R.
- nomilk 5y agoInteresting. I must admit I've never used substitute. I tried dims but: Error in dims(iris) : could not find function "dims" I do find the occasional oddity. I've noticed more very useful messages/warnings (particularly in common tidyverse functions) recently, so I think they help. To be fair, these quirks are generally very uncommon in day to day use.
- nojito 5y agoYou may want to check out substitute2 which is much easier to use. https://rdatatable.gitlab.io/data.table/reference/substitute2.html https://rdatatable.gitlab.io/data.table/reference/substitute...
- sin7 5y ago1*0 = 1 1*1 = 1 1*-1 = 1 2*0 = 1 2*1 = 2 2*-1 = 1/2 When 1 raised to any power equals 1, does the power matter at all? Even if it's unknown, the answer is 1.
- nosianu 5y agoIt works and is IMO quite okay because NA is not the same as NaN (not a number). NA _does_ actually stand for a number, it's just that we don't know it. Which is an interesting detail in R that should be mentioned anyway, the difference between NA and NaN. Anyone used to languages which just NaN may confuse NA for that non-value. https://www.r-bloggers.com/2012/08/difference-between-na-and-nan-in-r/ https://www.r-bloggers.com/2012/08/difference-between-na-and... https://cran.r-project.org/doc/manuals/r-release/R-lang.html#NA-handling https://cran.r-project.org/doc/manuals/r-release/R-lang.html... (lots of details how NA and NaN are handled) Except - 1^NaN also is 1... now that IMO is wrong. But you can try the same in your browser's JS console and you will get 1 as a result too, so R is not the only one. There are several NA values in R - NA_integer_, NA_real_, NA_complex_ and NA_character_, and the results will be different if you use some of them. NA_character_ and NA_complex_ will produce errors (different ones).
- _fnhr 5y agoAgree about 1^NaN being strange. Also R's cleverness with NA's is not so consistent. For example: median(c(1,1,1,NA)) Should return 1, since no matter what value is behind NA the median is still 1. But it returns NA.