0

How can I make it that R return to NA^0 = NA

NA*0 = NA
NA^0 = 1
NA^0.0000001 = NA
Phil
  • 7,287
  • 3
  • 36
  • 66
hamed
  • 9
  • 1
  • 1
    The provided "existing answer" will tell you _why_ this occurs, but doesn't explain how to change it, as you asked. You can write a custom function that checks if the input is NA, and if so returns NA, otherwise raises to the supplied power. – Paul Stafford Allen Nov 24 '22 at 09:39
  • 1
    You could redefine `^` to return `NA` if input is `NA` and return the normal value otherwise: `'^' <- function(x,y) ifelse(is.na(x),NA,.Primitive("^")(x,y))` – shaun_m Nov 24 '22 at 10:01
  • The title of your question and the body of your question ask two different questions. – Mark Rotteveel Nov 24 '22 at 15:20

0 Answers0