[R] Can I replace NA by 0 (if yes, how) ?

Wollkind, Steven Steven.Wollkind at GeodeCapital.com
Wed Nov 7 17:33:46 CET 2007

You don't need to loop.  You can just do

pfit$coefficients[is.na(pfit$coefficients)] <- 0 

Steve Wollkind
Associate Analyst
Geode Capital Management, LLC
1 Post Office Square / 28th Floor / Boston, MA 02109
steven.wollkind at geodecapital.com
Tel:   (617) 392-8991
Fax:  (617) 476-6389

This e-mail, and any attachments hereto, are intended for use by the
addressee(s) only and may contain information that is (i) confidential
information of Geode Capital Management, LLC and/or its affiliates,
and/or (ii) proprietary information of Geode Capital Management, LLC
and/or its affiliates. If you are not the intended recipient of this
e-mail, or if you have otherwise received this e-mail in error, please
immediately notify me by telephone (you may call collect), or by e-mail,
and please permanently delete the original, any print outs and any
copies of the foregoing. Any dissemination, distribution or copying of
this e-mail is strictly prohibited. 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Ptit_Bleu
Sent: Wednesday, November 07, 2007 11:28 AM
To: r-help at r-project.org
Subject: Re: [R] Can I replace NA by 0 (if yes, how) ?

I found this solution but it must another one much more "R-friendly" ?

for (a in 1:9) {
if (is.na(pfit$coefficients[[a]])) (pfit$coefficients[[a]]<-0)

Again thank you in advance for explainations concerning NA,
Ptit Bleu.
View this message in context:
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list