Skip to content
Prev 55749 / 398500 Next

replacing NA's with 0 in a dataframe for specified columns

I know that there must be a cool way of doing this, but I can't think
of it. Let's say I have an dataframe with NA's.
a  b  c
1  0  0 NA
2  1 NA  0
3  2  1  1
4 NA  2  2
I know it is easy to replace all the NA's with zeroes.
a b c
1 0 0 0
2 1 0 0
3 2 1 1
4 0 2 2
But how do I do this for just columns a and c, leaving the NA in
column b alone?

Thanks,

Dave Kane
_                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    9.1              
year     2004             
month    06               
day      21               
language R