Since nobody so far felt fit to point out why what you’re trying doesn’t work:
NA == NAdoesn’t return
TRUE, it returns
NA(since comparing to undefined values should yield an undefined result).
- You’re trying to call
applyon an atomic vector. You can’t use
applyto loop over the elements in a column.
- Your subscripts are off – you’re trying to give two indices into
a$x, which is just the column (an atomic vector).
I’d fix up 3. to get to
a$x[is.na(a$x)] <- 0