Skip to content
Prev 69837 / 398525 Next

NA erase your data trick

Anders Schwartz Corr wrote:
Not if you don't have it backed up somewhere else.

I wouldn't recommend keeping your only copy of anything in an R 
workspace.  It's too easy to accidentally delete or overwrite it.  Keep 
the original in a file.
For some values of i and n, this last line simplifies to

tcn5[TRUE] <- NA

which is why you lost your data.

You want to (a) think in vectors, or (b) use an if statement:

(a) Replace your whole series of statements with

tcn5[is.na(tcn5) | tcn5 == -9] <- NA

or

(b) Replace just the last line above with

   if (is.na(tcn5[n,i]) | tcn5[n,i] == -9) tcn5[n,i] <- NA

I'd choose (a); it's a lot cleaner and will run faster.

Duncan Murdoch