[R] replace NA value with 0

Gabor Csardi csardi at rmki.kfki.hu
Fri Sep 14 10:27:03 CEST 2007


x[ is.na(x) ] <- 0

should work in most cases i think.

Gabor

On Fri, Sep 14, 2007 at 10:08:19AM +0200, Alfredo Alessandrini wrote:
> Hi,
> 
> how can I replace NA value with 0:
> 
> 1991 217  119 103 109 137 202 283 240 146  NA
> 1992 270  174 149 144 166 239 278 237 275  NA
> 1993 146  111 104  89  98 131 153 148 175  NA
> 1994 177  123 146 124 121 200 266 191 240 106
> 1995 145   98  95  89  95 130 183 161 164 129
> 1996 145   98  89  90  93 138 158 131 161 161
> 
> 1991 217  119 103 109 137 202 283 240 146  0
> 1992 270  174 149 144 166 239 278 237 275  0
> 1993 146  111 104  89  98 131 153 148 175  0
> 1994 177  123 146 124 121 200 266 191 240 106
> 1995 145   98  95  89  95 130 183 161 164 129
> 1996 145   98  89  90  93 138 158 131 161 161
> 
> 
> Best wishes,
> 
> Alfredo
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    MTA RMKI, ELTE TTK



More information about the R-help mailing list