[R] Odp: Question regarding to replace <NA>

Petr PIKAL petr.pikal at precheza.cz
Tue Nov 9 20:44:41 CET 2010


Hi

r-help-bounces at r-project.org napsal dne 09.11.2010 18:33:54:

> Kate Hsu <yhsu.rhelp at gmail.com> 
> Odeslal: r-help-bounces at r-project.org
> 
> 09.11.2010 18:33
> 
> Komu
> 
> r-help at r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] Question regarding to replace <NA>
> 
> Dear r-users,
> 
> Basically, I have a data as follows,
> 
> > data
>        S s1 s2 s3 s4 s5      prob obs num.strata
> 1  NNNNN  N  N  N  N  N 0.0000108  32       <NA>
> 2  NNNNY  N  N  N  N  Y 0.0005292  16       <NA>
> 3  NNNYN  N  N  N  Y  N 0.0005292  24       <NA>
> 4  NNNYY  N  N  N  Y  Y 0.0259308   8          1
> ....
> 
> I want to replace <NA> by 0, when I tried the following command, I get 
som
> error message.
> data[is.na(data)]<-0
> 
> Warning message:
> In `[<-.factor`(`*tmp*`, thisvar, value = 0) :
>   invalid factor level, NAs generated

It is because num.strata is probably  factor see

str(data)

however there is usually no need for changing NA to zero as many (most, 
all?) functions have some kind of clever handling of missing values 
represented by NA.

regards
Petr




> 
> Anyone knows how to deal with this?
> 
> Thanks,
> 
> Kate
> 
>    [[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.



More information about the R-help mailing list