Re: [R] zoo object: replace NAs from another zoo object

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 13 Mar 2008 20:55:59 -0400

An example that included input and output would help. I'll take a guess but if that's not it please clarify and provide that.

Also its helpful if you can provide the data in easily copied form using dput(z).

I will assume that time(New) is a superset of time(Old) and "put them in" means replace the values in Old with those from New so that Old should be the same shape and have the same times before and after.

> library(zoo)
> Old <- zoo(matrix(1:10, 5))
> New <- zoo(matrix(c(NA, 12:16), 3))
> New.omit <- na.omit(New)
> window(Old, time(New.omit)) <- New.omit
> Old

1 1 6
2 12 15
3 13 16
4 4 9
5 5 10

On Thu, Mar 13, 2008 at 6:47 PM, Timothy W. Hilton <twh142_at_psu.edu> wrote:
> Hello,
>
> I have two zoo objects, new and old, indexed by chron objects. Their structure is like this:
>
> (05/25/06 00:00:00) NA NA NA
> (05/25/06 00:02:00) 948.20 24.198 0
> (05/25/06 00:04:00) 948.26 20.640 0
> (05/25/06 00:06:00) 948.37 19.653 0
> (05/25/06 00:08:00) 948.48 19.135 0
> (05/25/06 00:10:00) 948.54 22.510 0
> (05/25/06 00:12:00) 948.55 27.175 0
> (05/25/06 00:14:00) 948.46 30.075 0
> (05/25/06 00:16:00) 948.59 28.815 0
> (05/25/06 00:18:00) 948.96 27.938 0
>
> old spans a larger range of dates than new. I would like to take all the values in new that are not NA and place them in old, matching the time indices. I have tried a number of variations on the themes of merge and replace, but can't get them to work, and the brute force for loop solution is unnacceptably slow. Could someone suggest a solution?
>
> Many thanks,
> Tim
>
> ______________________________________________
> 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.
>



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. Received on Fri 14 Mar 2008 - 00:59:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 14 Mar 2008 - 11:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive