Since nobody so far felt fit to point out why what you’re trying doesn’t work:
NA == NA
doesn’t returnTRUE
, it returnsNA
(since comparing to undefined values should yield an undefined result).- You’re trying to call
apply
on an atomic vector. You can’t useapply
to 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