Home > Software engineering >  Removing NA value with if else condition and for loop
Removing NA value with if else condition and for loop

Time:11-24

I am trying to remove the NA value. I know there are other ways to do it but, for practice, I am using this method.

cost <- c(30000, 35000, 50000, 60000, 70000, 50000, 50000)
new_revenue <- c()

for (i in revenue) {if (i != NA) {new_revenue <- c(new_revenue, i)}}```

But I am getting this error below:
Error in if (i != NA) { : missing value where TRUE/FALSE needed

What am I doing wrong?

CodePudding user response:

use !is.na(i) instead of i != NA

  •  Tags:  
  • r
  • Related