What is the structure of the data that you are reading in?  Are you using
'read.table', 'scan', etc.?  Are all the columns numeric, or do you just
want to change some of them?  If you have used 'na.strings' to cause the
values of the missing data to be set to NA, then you can iterate through the
appropriate columns to change NAs to zero, but this depends on your
structure.  For example if you know the names of the columns, you could do:

for (i in c('col1', 'col3', 'col8')) df[[i]][is.na(df[[i]])] <- 0

On Tue, Jan 12, 2010 at 1:06 PM, karena <dr.jzhou@gmail.com> wrote:

>
> Hi, tim,
>
> thank you very much for the reply, but I am really a new user. How to
> change
> all NAs to zero?
>
> thanks again.
>
> karena
>
>
> jholtman wrote:
> >
> > ?read.table
> >
> > na.strings='.'
> >
> > Then change all NAs to zero     df$col[is.na(df$col)] <- 0
> >
> > On Tue, Jan 12, 2010 at 12:46 PM, karena <dr.jzhou@gmail.com> wrote:
> >
> >>
> >> hi, I have a question about importing data in R.
> >>
> >> I want to import a file which has missing value in it, and the missing
> >> values are denoted as ".", I want to first read in the file, and then
> >> change
> >> the "." into the number zero "0".
> >>
> >> how can I do that?
> >>
> >> thank you,
> >>
> >> karena
> >> --
> >> View this message in context:
> >>
> http://n4.nabble.com/how-to-handle-missing-values-when-importing-data-in-R-tp1012298p1012298.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> ______________________________________________
> >> R-help@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<http://www.r-project.org/posting-guide.html>
> <http://www.r-project.org/posting-guide.html>
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem that you are trying to solve?
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> --
> View this message in context:
> http://n4.nabble.com/how-to-handle-missing-values-when-importing-data-in-R-tp1012298p1012318.html
>  Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

