0

Title says it all, I created a composite index which has some NaN's in it. How would I go on and remove theses NaN's from a specific column (my composite index)?

I have looked at is.nan() but that just tells me if it's NaN or not...

FALA
  • 11
  • 3
  • 1
    Does this answer your question? [How to replace NaN value with zero in a huge data frame?](https://stackoverflow.com/questions/18142117/how-to-replace-nan-value-with-zero-in-a-huge-data-frame) – divibisan Jan 20 '22 at 20:48

1 Answers1

0

You can use an if-else statement with is.nan() as the conditional and set the value to 0 on true else set the value to the number.

More information here: Does the ternary operator exist in R?

From the link, credit to the author of that accepted answer for the following example(s) of code:

if-else

> x <- if(a==1) 1 else 2
> x
[1] 1
> x <- if(a==2) 1 else 2
> x
[1] 2