[R] Merge failure using zoo package
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Apr 2 18:52:01 CEST 2010
Below is the format that was requested. This has the data followed by
the corrected code at the end. There are several things that were
wrong:
1. z1[,2] is wrong since z1 is a vector, not a 2d matrix. Ditto for
z2. Ideally zoo would have given an error message but in any case its
wrong. It should be just z1.
2. The merge works ok but the second argument to na.approx should be
xout=time(z1). xout= was missing.
3. there were a number of bugs removed from na.approx in the devel
version of zoo. I don't think they impact this but if you have any
problems with na.approx then uncomment the source statement in the
code below. It will bring in the development version of na.approx into
your workspace.
Lines1 <- "time1,dataset1
01:01:00,0.73512097
01:01:30,0.34860813
01:02:00,0.61306418
01:02:30,0.01495898
01:03:00,0.27035612
01:03:30,0.69513898
01:04:00,0.46451758
01:04:30,0.61672569
01:05:00,0.82496122
01:05:30,0.34766154
01:06:00,0.69618714
01:06:30,0.39035214
01:07:00,0.01680143
01:07:30,0.28576967
01:08:00,0.01205416
01:08:30,0.89637254
01:09:00,0.63147653
01:09:30,0.01522139
01:10:00,0.27661960
01:10:30,0.50974124
01:11:00,0.68141977
01:11:30,0.90725854
01:12:00,0.83823443
01:12:30,0.53360241
01:13:00,0.17769196
01:13:30,0.83438616
01:14:00,0.67248807
01:14:30,0.09991933
01:15:00,0.03334966
01:15:30,0.93292355
01:16:00,0.15990837
01:16:30,0.05354050
01:17:00,0.55281203
01:17:30,0.37845690
01:18:00,0.89051365
01:18:30,0.16674292
01:19:00,0.85458626
01:19:30,0.19278550
01:20:00,0.73240405
01:20:30,0.16417524
01:21:00,0.73878212
01:21:30,0.51790118
01:22:00,0.83076438
01:22:30,0.47555504
01:23:00,0.02108640
01:23:30,0.82911053
01:24:00,0.95555646
01:24:30,0.14493657
01:25:00,0.84422332
01:25:30,0.41589974
01:26:00,0.67606367
01:26:30,0.00606434
01:27:00,0.59951991
01:27:30,0.43949260
01:28:00,0.66297385
01:28:30,0.33131298
01:29:00,0.06102041
01:29:30,0.84722118
01:30:00,0.46841491
01:30:30,0.34200755
01:31:00,0.87386578
01:31:30,0.70737403
01:32:00,0.23978781
01:32:30,0.11787278
01:33:00,0.14679814
01:33:30,0.65217063
01:34:00,0.81355908
01:34:30,0.31583482
01:35:00,0.92167666
01:35:30,0.55931271
01:36:00,0.13641271
01:36:30,0.35048575
01:37:00,0.17243584
01:37:30,0.93645686
01:38:00,0.85356548
01:38:30,0.61399352
01:39:00,0.05910707
01:39:30,0.01721605
01:40:00,0.94845557
01:40:30,0.48117810
01:41:00,0.34752402
01:41:30,0.59295472
01:42:00,0.64267429
01:42:30,0.57859933
01:43:00,0.00201441
01:43:30,0.32530995
01:44:00,0.25474645
01:44:30,0.93187534
01:45:00,0.99361033
01:45:30,0.16591641"
Lines2 <- "time2,dataset2
01:01:01,0.17558467
01:01:42,0.23806514
01:02:23,0.75867726
01:03:06,0.73502357
01:03:50,0.94018206
01:04:35,0.61882643
01:05:21,0.68417492
01:06:08,0.05744461
01:06:55,0.33344394
01:07:44,0.68752593
01:08:33,0.17270469
01:09:23,0.81522124
01:10:03,0.68304352
01:10:43,0.38774082
01:11:23,0.84176890
01:12:04,0.09344446
01:12:44,0.13431965
01:13:25,0.92210721
01:14:06,0.33630635
01:14:47,0.56690294
01:15:29,0.09870816
01:16:11,0.77864105
01:16:53,0.61803441
01:17:35,0.09133728
01:18:17,0.08925487
01:19:00,0.89271117
01:19:42,0.56605742
01:20:25,0.98520534
01:21:08,0.66104843
01:21:51,0.96948589
01:22:34,0.05692690
01:23:17,0.71887456
01:24:00,0.14903741
01:24:43,0.86569445
01:25:26,0.27923513
01:26:09,0.98365033
01:26:53,0.08308399
01:27:36,0.87071027
01:28:19,0.26475705
01:29:03,0.76409811
01:29:47,0.59563256
01:30:31,0.23995054
01:31:14,0.00951054
01:31:59,0.21367270"
Lines3 <- "time1,dataset1
01:02:30,0.01495898
01:03:00,0.27035612
01:03:30,0.69513898
01:04:00,0.46451758
01:04:30,0.61672569
01:05:00,0.82496122
01:05:30,0.34766154
01:06:00,0.69618714
01:06:30,0.39035214
01:07:00,0.01680143
01:07:30,0.28576967
01:08:00,0.01205416
01:08:30,0.89637254
01:09:00,0.63147653
01:09:30,0.01522139
01:10:00,0.27661960
01:10:30,0.50974124
01:11:00,0.68141977
01:11:30,0.90725854
01:12:00,0.83823443
01:12:30,0.53360241
01:13:00,0.17769196
01:13:30,0.83438616
01:14:00,0.67248807
01:14:30,0.09991933
01:15:00,0.03334966
01:15:30,0.93292355
01:16:00,0.15990837
01:16:30,0.05354050
01:17:00,0.55281203
01:17:30,0.37845690
01:18:00,0.89051365
01:18:30,0.16674292
01:19:00,0.85458626
01:19:30,0.19278550
01:20:00,0.73240405
01:20:30,0.16417524
01:21:00,0.73878212
01:21:30,0.51790118
01:22:00,0.83076438
01:22:30,0.47555504
01:23:00,0.02108640
01:23:30,0.82911053
01:24:00,0.95555646
01:24:30,0.14493657
01:25:00,0.84422332
01:25:30,0.41589974
01:26:00,0.67606367
01:26:30,0.00606434
01:27:00,0.59951991
01:27:30,0.43949260
01:28:00,0.66297385
01:28:30,0.33131298
01:29:00,0.06102041
01:29:30,0.84722118
01:30:00,0.46841491
01:30:30,0.34200755
01:31:00,0.87386578
01:31:30,0.70737403
01:32:00,0.23978781
01:32:30,0.11787278
01:33:00,0.14679814
01:33:30,0.65217063
01:34:00,0.81355908
01:34:30,0.31583482
01:35:00,0.92167666
01:35:30,0.55931271
01:36:00,0.13641271
01:36:30,0.35048575
01:37:00,0.17243584
01:37:30,0.93645686
01:38:00,0.85356548
01:38:30,0.61399352
01:39:00,0.05910707
01:39:30,0.01721605
01:40:00,0.94845557
01:40:30,0.48117810
01:41:00,0.34752402
01:41:30,0.59295472
01:42:00,0.64267429
01:42:30,0.57859933
01:43:00,0.00201441
01:43:30,0.32530995
01:44:00,0.25474645
01:44:30,0.93187534
01:45:00,0.99361033
01:45:30,0.16591641"
Lines4 <- "time2,dataset2
01:03:06,0.73502357
01:03:50,0.94018206
01:04:35,0.61882643
01:05:21,0.68417492
01:06:08,0.05744461
01:06:55,0.33344394
01:07:44,0.68752593
01:08:33,0.17270469
01:09:23,0.81522124
01:10:03,0.68304352
01:10:43,0.38774082
01:11:23,0.84176890
01:12:04,0.09344446
01:12:44,0.13431965
01:13:25,0.92210721
01:14:06,0.33630635
01:14:47,0.56690294
01:15:29,0.09870816
01:16:11,0.77864105
01:16:53,0.61803441
01:17:35,0.09133728
01:18:17,0.08925487
01:19:00,0.89271117
01:19:42,0.56605742
01:20:25,0.98520534
01:21:08,0.66104843
01:21:51,0.96948589
01:22:34,0.05692690
01:23:17,0.71887456
01:24:00,0.14903741
01:24:43,0.86569445
01:25:26,0.27923513
01:26:09,0.98365033
01:26:53,0.08308399
01:27:36,0.87071027
01:28:19,0.26475705
01:29:03,0.76409811
01:29:47,0.59563256
01:30:31,0.23995054
01:31:14,0.00951054
01:31:59,0.21367270"
library(chron)
library(zoo)
z1<-read.zoo(textConnection(Lines1),header=TRUE,sep=",",FUN=times)
z2<-read.zoo(textConnection(Lines2),header=TRUE,sep=",",FUN=times)
z12 <- merge(z1, z2)
# source("http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/zoo/R/na.approx.R?rev=676&root=zoo")
z3<-na.approx(z12,xout=time(z1))
On Fri, Apr 2, 2010 at 12:19 PM, e-letter <inpost at gmail.com> wrote:
> On 02/04/2010, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
>> The code does not run with the files. I need the requested
>> information, namely a single file containing code and data and that I
>> can just copy into a session without editing and see the result you
>> see.
>
> I don't understand how I can combine the four csv files into a single
> file of data and terminal commands? Anyway, further terminal output.
>
> The following also occurs with correction of the commands. The data
> merge is incomplete (to 1:27:30); data set 1 ends at time 1:45:30;
> data set 2 1:31:59
>
>> library(chron)
>> library(zoo)
>> z1<-read.zoo("test1.csv",header=TRUE,sep=",",FUN=times)
>> z2<-read.zoo("test2.csv",header=TRUE,sep=",",FUN=times)
>> z3<-(na.approx(merge(z1[,2],z2[,2]),time(z1)))
>> z3
> z1[, 2] z2[, 2]
> 01:01:01 0.54186455 0.17558467
> 01:01:30 0.34860813 0.20682491
> 01:01:42 0.48083615 0.23806514
> 01:02:00 0.61306418 0.49837120
> 01:02:23 0.31401158 0.75867726
> 01:02:30 0.01495898 0.75079270
> 01:03:00 0.27035612 0.74290813
> 01:03:06 0.48274755 0.73502357
> 01:03:30 0.69513898 0.83760282
> 01:03:50 0.57982828 0.94018206
> 01:04:00 0.46451758 0.83306352
> 01:04:30 0.61672569 0.72594497
> 01:04:35 0.72084346 0.61882643
> 01:05:00 0.82496122 0.65150068
> 01:05:21 0.58631138 0.68417492
> 01:05:30 0.34766154 0.47526482
> 01:06:00 0.69618714 0.26635471
> 01:06:08 0.54326964 0.05744461
> 01:06:30 0.39035214 0.19544428
> 01:06:55 0.20357679 0.33344394
> 01:07:00 0.01680143 0.45147127
> 01:07:30 0.28576967 0.56949860
> 01:07:44 0.14891191 0.68752593
> 01:08:00 0.01205416 0.51591885
> 01:08:30 0.89637254 0.34431177
> 01:08:33 0.76392454 0.17270469
> 01:09:00 0.63147653 0.49396296
> 01:09:23 0.32334896 0.81522124
> 01:09:30 0.01522139 0.77116200
> 01:10:00 0.27661960 0.72710276
> 01:10:03 0.39318042 0.68304352
> 01:10:30 0.50974124 0.53539217
> 01:10:43 0.59558051 0.38774082
> 01:11:00 0.68141977 0.61475486
> 01:11:23 0.79433915 0.84176890
> 01:11:30 0.90725854 0.59232742
> 01:12:00 0.83823443 0.34288594
> 01:12:04 0.68591842 0.09344446
> 01:12:30 0.53360241 0.11388206
> 01:12:44 0.35564718 0.13431965
> 01:13:00 0.17769196 0.52821343
> 01:13:25 0.50603906 0.92210721
> 01:13:30 0.83438616 0.72684026
> 01:14:00 0.67248807 0.53157330
> 01:14:06 0.38620370 0.33630635
> 01:14:30 0.09991933 0.45160464
> 01:14:47 0.06663450 0.56690294
> 01:15:00 0.03334966 0.33280555
> 01:15:29 0.48313660 0.09870816
> 01:15:30 0.93292355 0.32535246
> 01:16:00 0.15990837 0.55199675
> 01:16:11 0.10672443 0.77864105
> 01:16:30 0.05354050 0.69833773
> 01:16:53 0.30317627 0.61803441
> 01:17:00 0.55281203 0.44246870
> 01:17:30 0.37845690 0.26690299
> 01:17:35 0.63448528 0.09133728
> 01:18:00 0.89051365 0.09029608
> 01:18:17 0.52862829 0.08925487
> 01:18:30 0.16674292 0.49098302
> 01:19:00 0.85458626 0.89271117
> 01:19:30 0.19278550 0.72938430
> 01:19:42 0.46259477 0.56605742
> 01:20:00 0.73240405 0.77563138
> 01:20:25 0.44828965 0.98520534
> 01:20:30 0.16417524 0.87715304
> 01:21:00 0.73878212 0.76910073
> 01:21:08 0.62834165 0.66104843
> 01:21:30 0.51790118 0.81526716
> 01:21:51 0.67433278 0.96948589
> 01:22:00 0.83076438 0.66529956
> 01:22:30 0.47555504 0.36111323
> 01:22:34 0.24832072 0.05692690
> 01:23:00 0.02108640 0.38790073
> 01:23:17 0.42509847 0.71887456
> 01:23:30 0.82911053 0.43395599
> 01:24:00 0.95555646 0.14903741
> 01:24:30 0.14493657 0.50736593
> 01:24:43 0.49457995 0.86569445
> 01:25:00 0.84422332 0.57246479
> 01:25:26 0.63006153 0.27923513
> 01:25:30 0.41589974 0.51404020
> 01:26:00 0.67606367 0.74884526
> 01:26:09 0.34106401 0.98365033
> 01:26:30 0.00606434 0.53336716
> 01:26:53 0.30279212 0.08308399
> 01:27:00 0.59951991 0.34562608
> 01:27:30 0.43949260 0.60816818
>>
>
More information about the R-help
mailing list