[R] How to replace NA values

Bert Gunter gunter.berton at gene.com
Sun Aug 4 18:15:45 CEST 2013


... and learn to use the Help system to avoid wasting space on this
list and wasting your time waiting for an answer.

?NA

(what else?!) would have immediately gotten what you were looking for.

Cheers,
Bert

On Sun, Aug 4, 2013 at 9:09 AM, William Revelle <lists at revelle.net> wrote:
> Bruce,
>   use the is.na function, e.g.,
>
>
> Bats.cast[is.na(Bats.cast)] <- 0
>
> Bill
> On Jul 28, 2013, at 8:12 AM, Bruce Miller <batsncats 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 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.
>>
>>
>>
>>       [[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.
>>
>
> William Revelle                    http://personality-project.org/revelle.html
> Professor                                  http://personality-project.org
> Department of Psychology   http://www.wcas.northwestern.edu/psych/
> Northwestern University    http://www.northwestern.edu/
> Use R for psychology             http://personality-project.org/r
> It is 5 minutes to midnight        http://www.thebulletin.org
>
> ______________________________________________
> 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