[R] filling small gaps of N/A

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 3 19:30:27 CEST 2012


On Tue, Apr 3, 2012 at 4:52 AM, jeff6868
<geoffrey_klein at etu.u-bourgogne.fr> wrote:
> Hi everybody,
>
> I'm a new R french user. Sorry if my english is not perfect. Hope you'll
> understand my problem ;)
>
> I have to work on temperature data (35000 lines in one file) containing some
> missing data (N/A). Sometimes I have only 2 or 3 N/A following each other,
> but I have also sometimes 100 or 200 N/A following each other. Here's an
> example of my data, when I have only small gaps of missing data (2 or 3
> N/A):
>
> 09/01/2008 12:00   2   1.93   2.93   4.56   5.43
> 09/01/2008 12:15   2   *3.93*   3.25   4.93   5.56
> 09/01/2008 12:30   2    NA   3.5   5.06   5.56
> 09/01/2008 12:45   2    NA   3.68 5.25   5.68
> 09/01/2008 13:00   2   *4.93 *  3.87   5.56   5.93
> 09/01/2008 13:15   2   5.93   4.25   5.75   6.06
> 09/01/2008 13:30   2   3.93   4.56   5.93   6.18
>
> My question is: how can I replace these small gaps of N/A by numeric values?
> I would like a fonction which only replace the small gaps (2 or 3 N/A) in my
> data, but not the big gaps (more than 5 N/A following each other).
>

Try na.locf, na.approx or na.spline in the zoo package noting the
maxgap= argument on each.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list