-1

I am creating a plot in r and have to replace the NA values with a small number like 1e-10. I need to overwrite the NA (or Infinite Value, which is what you get if you try to make R do math with NA) in the Adjusted fold change code, by using is.na() or is.infinite().

The data frame name is WVLyme. I tried the following code:

ADJ<-which(WVLyme,is.na(1e-10))

then I tried:

WVLyme[is.na(WVLyme)] <- 1^-10

but when I tried to do the fold change code after:

with(WVLyme,max(RawFChange)

nothing came up and I got an error.

{r}
WVLyme[is.na(WVLyme)] <- 1^-10
with(WVLyme,max(RawFChange)

Error: unexpected ',' in "WVLyme[is.na(WVLyme)] <- 1^-10,"

vurmux
  • 9,420
  • 3
  • 25
  • 45
spethy39
  • 3
  • 1
  • 1
    Several easily fixed typos/errors: The error message `Error: unexpected ',' in "WVLyme[is.na(WVLyme)] <- 1^-10,"` makes it appear you have a stray comma. `1e-10` and `1^-10` are not the same thing. You're missing a closing `)` at the end of your `with` call. It's really helpful if you check for typos before posting. Also [see here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making a reproducible question – camille Apr 23 '19 at 17:25
  • I apologize for the errors, I know what the error messages mean and I know I was missing an end parenthesis,, but the code was not working even when fixing those issues. The code was not the correct code overall. I was out a week in class and I'm just trying to understand the assignment. Thanks... – spethy39 Apr 23 '19 at 20:18
  • Okay, but why post code that you know has typos, rather than fixing the typos before posting? That just adds to the work of folks you're asking for help. – camille Apr 23 '19 at 20:28

1 Answers1

0

Using base R you can replace your NA with another value like this:

df[is.na(df)] <- Inf

    a   b
1 Inf Inf
2   1   1
3   2   2

Sample data:

df <- data.frame(a = c(NA, 1, 2), 
           b = c(NA, 1, 2))
DJV
  • 4,743
  • 3
  • 19
  • 34