[R] problem with NA and if
Keld J?rn Simonsen
keld at dkuug.dk
Fri Jul 4 14:12:20 CEST 2008
On Fri, Jul 04, 2008 at 04:44:53PM +1000, Andrew Robinson wrote:
> Hi Keld
>
> you should read ?sum.
>
> sum(c(1,2,NA), na.rm=TRUE)
Thanks, that solved my problem.
Best regars
keld
> Cheers
>
> Andrew
>
> On Fri, Jul 04, 2008 at 08:29:34AM +0200, Keld J?rn Simonsen wrote:
> > Hi
> >
> > I would like to sum a number of time series, some of them having NA's
> >
> > Standard action is here that if I sum a value with a NA, then the result
> > is NA. I would like it to just keep the value.
> >
> > I then try to:
> >
> > a = NA; if (a == NA) { a = 0}
> >
> > just to try it out, but it says
> >
> > Error in if (a == NA) { : missing value where TRUE/FALSE needed
> >
> > What is wrong, and can I do it smarter? I looked at na.action but I
> > don't see how it affects addition of vectors, nor time series.
> >
> > Best regards
> > keld
> >
> > ______________________________________________
> > 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.
>
> --
> Andrew Robinson
> Department of Mathematics and Statistics Tel: +61-3-8344-6410
> University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599
> http://www.ms.unimelb.edu.au/~andrewpr
> http://blogs.mbs.edu/fishing-in-the-bay/
More information about the R-help
mailing list