lundi 5 octobre 2015

How to evaluate a NA value in an if statement in R?

I have a dataset and I need to use an IF statement to evaluate every value in the 5th column. If it is positive, it should say 'Up' otherwise it should say 'Not up'. The problem is that at the end of each day I would have 5 NA values and my statement does not know how to evaluate those. My dataset would look something like:

 379    949 2115    2015-02-20  0   Not Up
 380    950 2115    2015-02-20  -5  Not Up
 381    951 2115    2015-02-20  -5  Not Up
 382    952 2115    2015-02-20  -5  Not Up
 383    953 2115    2015-02-20  -5  Not Up
 384    954 2115    2015-02-20  -5  Not Up
 385    955 2110    2015-02-20  0   Not Up
 386    956 2110    2015-02-20  NA  Up
 387    957 2110    2015-02-20  NA  Up
 388    958 2110    2015-02-20  NA  Up
 389    959 2110    2015-02-20  NA  Up
 390    960 2110    2015-02-20  NA  Up
 391    571 2075    2015-02-23  15  Up
 392    572 2075    2015-02-23  15  Up
 393    573 2085    2015-02-23  0   Up
 394    574 2085    2015-02-23  -5  Up
 395    575 2085    2015-02-23  -5  Up
 396    576 2090    2015-02-23  -15 Up
 397    577 2090    2015-02-23  -20 Up

As you can see, after the NA values the If statement fails to evaluate and output what I need correctly.

Any help on how to deal with the 'NA' values would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire