[R] How to replace NA values

Bert Gunter gunter.berton at gene.com
Sun Jul 28 15:37:09 CEST 2013


Inline.

--Bert

On Sun, Jul 28, 2013 at 6:19 AM, Neotropical bat risk assessments
<neotropical.bats at gmail.com> wrote:
> Hi all,
>
> I am using reshape2 to reformat a data frame and all is great using:
>
> Bats.melt <- melt(data = Bats)
>
> Bats.cast <- dcast(data = Bats.melt, formula = Species ~ Location)
>
> dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj')
>
> write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv')
>
>
> The resulting file from both dput and write are great, however in order
> to run another R analysis I need to replace all the NA values in the
> output with a zero - 0 value.

I strongly suspect this is false. Most R functions have options to
deal with NA, alas, not consistently though.
See, e.g.  ?na.omit  . For manual processing, see ?NA (of course!).

However, replacing NA's with 0's is dangerous. It may also be
scientifically/statistically flawed; although properly dealing with
missing data can be a very difficult issue.

Cheers,
Bert

>
> I have just been opening this in Excel and using a simple find NA
> replace with 0 and saving then reopening in R.
>
> There must be a simple way to do this in R.
>
> Any suggestions welcomed.
>
>
>
> --
> Bruce W. Miller, PhD.
> Neotropical bat risk assessments
>
> If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet
>
> Using acoustic sampling to map species distributions for >15 years.
>
> Providing Interactive identification keys to the vocal signatures of New World Bats
>
> For various project details see:
>
> https://sites.google.com/site/batsoundservices/
>
>
>         [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm



More information about the R-help mailing list