Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Dieter Menne


Megh wrote:
 
 Dear all, I have following 2 zoo objects. However when I try to merge
 those 2 objects into one, nothing is coming as intended. Please see below
 the objects as well as the merged object:
 
 
 merge(dat11, dat22)
 V2.dat11 V3.dat11 V4.dat11 V5.dat11 V2.dat22 V3.dat22
 V4.dat22 V5.dat22
 2010-10-15 12:09:12   NA   NA   NA   NA   NA   NA 
  
 NA   NA
 
Since the simulated example works, it must have to do with your data. Try
str(dat11), str(dat12), maybe something strange has crept in.

Dieter


library(zoo)
x.date - as.Date(paste(2003, 02, c(1, 3, 7, 9, 14), sep = -))
x - zoo(matrix(1:10, ncol = 2), x.date)
x
str(x)

y.date - as.Date(paste(2006, 02, c(1, 3, 7, 9, 14), sep = -))
y - zoo(matrix(11:20, ncol = 2), y.date)
y
str(y)

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-merging-two-zoo-objects-tp2997472p2997494.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Achim Zeileis



On Fri, 15 Oct 2010, Megh Dal wrote:


Dear all, I have following 2 zoo objects. However when I try to merge those 2 
objects into one, nothing is coming as intended. Please see below the objects 
as well as the merged object:



dat11

 V2   V3   V4   V5
2010-10-15 13:43:54 73.8 73.8 73.8 73.8
2010-10-15 13:44:15 73.8 73.8 73.8 73.8
2010-10-15 13:45:51 73.8 73.8 73.8 73.8
2010-10-15 13:46:21 73.8 73.8 73.8 73.8
2010-10-15 13:47:27 73.8 73.8 73.8 73.8
2010-10-15 13:47:54 73.8 73.8 73.8 73.8
2010-10-15 13:49:51 73.7 73.7 73.7 73.7

dat22

 V2   V3   V4   V5
2010-10-15 12:09:12 74.0 74.0 74.0 74.0
2010-10-15 12:09:33 73.9 73.9 73.9 73.9
2010-10-15 12:20:36 74.0 74.0 74.0 74.0
2010-10-15 12:30:36 74.0 74.0 74.0 74.0
2010-10-15 12:41:03 73.7 73.7 73.7 73.7

merge(dat11, dat22)

   V2.dat11 V3.dat11 V4.dat11 V5.dat11 V2.dat22 V3.dat22 
V4.dat22 V5.dat22
2010-10-15 12:09:12   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 12:09:33   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:43:54   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:44:15   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:45:51   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:46:21   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:47:27   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:47:54   NA   NA   NA   NA   NA   NA   
NA   NA
2010-10-15 13:49:51   NA   NA   NA   NA   NA   NA   
NA   NA
Warning messages:
1: In MATCH(x, x) == seq_len(length(x)) :
 longer object length is not a multiple of shorter object length
2: In MATCH(x, x) == seq_len(length(x)) :
 longer object length is not a multiple of shorter object length

If somebody points me whether I went wrong, it would be really great.


merge() does cbind() (among some more general computations), I guess you 
want rbind().


Try rbind(dat11, dat22).

hth,
Z


Thanks

__
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
and provide commented, minimal, self-contained, reproducible code.



__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Gabor Grothendieck
On Fri, Oct 15, 2010 at 2:20 PM, Megh Dal megh700...@yahoo.com wrote:
 Dear all, I have following 2 zoo objects. However when I try to merge those 2 
 objects into one, nothing is coming as intended. Please see below the objects 
 as well as the merged object:


 dat11
                      V2   V3   V4   V5
 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
 2010-10-15 13:49:51 73.7 73.7 73.7 73.7
 dat22
                      V2   V3   V4   V5
 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
 2010-10-15 12:41:03 73.7 73.7 73.7 73.7
 merge(dat11, dat22)
                    V2.dat11 V3.dat11 V4.dat11 V5.dat11 V2.dat22 V3.dat22 
 V4.dat22 V5.dat22
 2010-10-15 12:09:12       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 12:09:33       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:43:54       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:44:15       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:45:51       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:46:21       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:47:27       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:47:54       NA       NA       NA       NA       NA       NA     
   NA       NA
 2010-10-15 13:49:51       NA       NA       NA       NA       NA       NA     
   NA       NA
 Warning messages:
 1: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter object length
 2: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter object length

 If somebody points me whether I went wrong, it would be really great.


If I try it then it works properly so there is likely something wrong
with your dat11 and dat22 objects.  If you provide the problem
reproducibly one might be able to say more.

 Lines1 - Date Time V2   V3   V4   V5
+ 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
+ 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
+ 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:49:51 73.7 73.7 73.7 73.7

 Lines2 - Date Time V2   V3   V4   V5
+ 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
+ 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
+ 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:41:03 73.7 73.7 73.7 73.7

 library(zoo)
 dat1 - read.zoo(textConnection(Lines1), header = TRUE,
+ index = list(1, 2), FUN = function(d, t) as.POSIXct(paste(d, t)))
Warning messages:
1: closing unused connection 8 (Lines2)
2: closing unused connection 7 (Lines1)
3: closing unused connection 5 (Lines2)
4: closing unused connection 4 (Lines1)
5: closing unused connection 3 (Lines2)
 dat2 - read.zoo(textConnection(Lines2), header = TRUE,
+ index = list(1, 2), FUN = function(d, t) as.POSIXct(paste(d, t)))
 merge(dat1, dat2)
V2.dat1 V3.dat1 V4.dat1 V5.dat1 V2.dat2 V3.dat2
V4.dat2 V5.dat2
2010-10-15 12:09:12  NA  NA  NA  NA74.074.0
74.074.0
2010-10-15 12:09:33  NA  NA  NA  NA73.973.9
73.973.9
2010-10-15 12:20:36  NA  NA  NA  NA74.074.0
74.074.0
2010-10-15 12:30:36  NA  NA  NA  NA74.074.0
74.074.0
2010-10-15 12:41:03  NA  NA  NA  NA73.773.7
73.773.7
2010-10-15 13:43:5473.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:44:1573.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:45:5173.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:46:2173.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:47:2773.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:47:5473.873.873.873.8  NA  NA
  NA  NA
2010-10-15 13:49:5173.773.773.773.7  NA  NA
  NA  NA

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
Hi Gabor, please see the attached files which is in text format. I have opened 
them on excel then, used clipboard to load them into R. Still really unclear 
what to do.

Also can you please elaborate this term index = list(1, 2), FUN = function(d, 
t) as.POSIXct(paste(d, t)) in your previous file? In help, it is given 
that:If FUN is specified then read.zoo calls FUN with the index as the first 
argument. I really could not connect your syntax with help.

--- On Sat, 10/16/10, Gabor Grothendieck ggrothendi...@gmail.com wrote:

 From: Gabor Grothendieck ggrothendi...@gmail.com
 Subject: Re: [R] Problem with merging two zoo objects
 To: Megh Dal megh700...@yahoo.com
 Cc: r-h...@stat.math.ethz.ch
 Date: Saturday, October 16, 2010, 12:11 AM
 On Fri, Oct 15, 2010 at 2:20 PM, Megh
 Dal megh700...@yahoo.com
 wrote:
  Dear all, I have following 2 zoo objects. However when
 I try to merge those 2 objects into one, nothing is coming
 as intended. Please see below the objects as well as the
 merged object:
 
 
  dat11
                       V2   V3   V4   V5
  2010-10-15 13:43:54 73.8 73.8 73.8 73.8
  2010-10-15 13:44:15 73.8 73.8 73.8 73.8
  2010-10-15 13:45:51 73.8 73.8 73.8 73.8
  2010-10-15 13:46:21 73.8 73.8 73.8 73.8
  2010-10-15 13:47:27 73.8 73.8 73.8 73.8
  2010-10-15 13:47:54 73.8 73.8 73.8 73.8
  2010-10-15 13:49:51 73.7 73.7 73.7 73.7
  dat22
                       V2   V3   V4   V5
  2010-10-15 12:09:12 74.0 74.0 74.0 74.0
  2010-10-15 12:09:33 73.9 73.9 73.9 73.9
  2010-10-15 12:20:36 74.0 74.0 74.0 74.0
  2010-10-15 12:30:36 74.0 74.0 74.0 74.0
  2010-10-15 12:41:03 73.7 73.7 73.7 73.7
  merge(dat11, dat22)
                     V2.dat11 V3.dat11
 V4.dat11 V5.dat11 V2.dat22 V3.dat22 V4.dat22 V5.dat22
  2010-10-15 12:09:12       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 12:09:33       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:43:54       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:44:15       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:45:51       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:46:21       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:47:27       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:47:54       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  2010-10-15 13:49:51       NA       NA      
 NA       NA       NA       NA       NA      
 NA
  Warning messages:
  1: In MATCH(x, x) == seq_len(length(x)) :
   longer object length is not a multiple of shorter
 object length
  2: In MATCH(x, x) == seq_len(length(x)) :
   longer object length is not a multiple of shorter
 object length
 
  If somebody points me whether I went wrong, it would
 be really great.
 
 
 If I try it then it works properly so there is likely
 something wrong
 with your dat11 and dat22 objects.  If you provide the
 problem
 reproducibly one might be able to say more.
 
  Lines1 - Date Time
 V2   V3   V4   V5
 + 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
 + 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
 + 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
 + 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
 + 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
 + 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
 + 2010-10-15 13:49:51 73.7 73.7 73.7 73.7
 
  Lines2 - Date Time
 V2   V3   V4   V5
 + 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
 + 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
 + 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
 + 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
 + 2010-10-15 12:41:03 73.7 73.7 73.7 73.7
 
  library(zoo)
  dat1 - read.zoo(textConnection(Lines1), header =
 TRUE,
 + index = list(1, 2), FUN = function(d, t)
 as.POSIXct(paste(d, t)))
 Warning messages:
 1: closing unused connection 8 (Lines2)
 2: closing unused connection 7 (Lines1)
 3: closing unused connection 5 (Lines2)
 4: closing unused connection 4 (Lines1)
 5: closing unused connection 3 (Lines2)
  dat2 - read.zoo(textConnection(Lines2), header =
 TRUE,
 + index = list(1, 2), FUN = function(d, t)
 as.POSIXct(paste(d, t)))
  merge(dat1, dat2)
                
     V2.dat1 V3.dat1 V4.dat1 V5.dat1 V2.dat2
 V3.dat2
 V4.dat2 V5.dat2
 2010-10-15 12:09:12      NA   
   NA      NA     
 NA    74.0    74.0
 74.0    74.0
 2010-10-15 12:09:33      NA   
   NA      NA     
 NA    73.9    73.9
 73.9    73.9
 2010-10-15 12:20:36      NA   
   NA      NA     
 NA    74.0    74.0
 74.0    74.0
 2010-10-15 12:30:36      NA   
   NA      NA     
 NA    74.0    74.0
 74.0    74.0
 2010-10-15 12:41:03      NA   
   NA      NA     
 NA    73.7    73.7
 73.7    73.7
 2010-10-15 13:43:54    73.8   
 73.8    73.8    73.8     
 NA      NA
   NA      NA
 2010-10-15 13:44:15    73.8   
 73.8    73.8    73.8     
 NA      NA
   NA      NA
 2010-10-15 13:45:51    73.8   
 73.8    73.8    73.8     
 NA      NA
   NA      NA
 2010-10

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh

I have compared dat11 and x using str() function, however did not find
drastic difference:


 str(dat11)
‘zoo’ series from 2010-10-15 13:43:54 to 2010-10-15 13:49:51
  Data: num [1:7, 1:4] 73.8 73.8 73.8 73.8 73.8 73.8 73.7 73.8 73.8 73.8 ...
 - attr(*, dimnames)=List of 2
  ..$ : chr [1:7] 7 6 5 4 ...
  ..$ : chr [1:4] V2 V3 V4 V5
  Index:  POSIXlt[1:7], format: 2010-10-15 13:43:54 2010-10-15 13:44:15
2010-10-15 13:45:51 2010-10-15 13:46:21 2010-10-15 13:47:27
2010-10-15 13:47:54 ...
 str(x)
‘zoo’ series from 2003-02-01 to 2003-02-14
  Data: int [1:5, 1:2] 1 2 3 4 5 6 7 8 9 10
  Index: Class 'Date'  num [1:5] 12084 12086 12090 12092 12097

Thanks,
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-merging-two-zoo-objects-tp2997472p2997510.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Achim Zeileis

On Fri, 15 Oct 2010, Megh Dal wrote:

Hi Gabor, please see the attached files which is in text format. I have 
opened them on excel then, used clipboard to load them into R. Still 
really unclear what to do.


I've read both files using read.zoo():

R z1 - read.zoo(dat1.txt, sep = ,, header = TRUE,
+format = %m/%d/%Y %H:%M:%S, tz = )
Warning message:
In zoo(rval3, ix) :
  some methods for zoo objects do not work if the index entries in 
'order.by' are not unique

R z2 - read.zoo(dat2.txt, sep = ,, header = TRUE,
+format = %m/%d/%Y %H:%M:%S, tz = )


Then, merge() does not work because some time indexes are not unique (and 
it would be unclear how these should be matched):


R merge(z1, z2)
Error in merge.zoo(z1, z2) :
  series cannot be merged with non-unique index entries in a series

However, you can remove the duplicated, e.g., by computing averages:

R z1a - aggregate(z1, time(z1), mean)

Then

R merge(z1a, z2)

works.

Also can you please elaborate this term index = list(1, 2), FUN = 
function(d, t) as.POSIXct(paste(d, t)) in your previous file? In help, 
it is given that:If FUN is specified then read.zoo calls FUN with the 
index as the first argument. I really could not connect your syntax 
with help.


The way Gabor read the data, the index was in two separate columns 
(columns 1 and 2). Hence, he specified

  index = list(1, 2)
and then provided a function that would return a POSIXct object when 
called with two arguments

  FUN(column1, column2)

hth,
Z


--- On Sat, 10/16/10, Gabor Grothendieck ggrothendi...@gmail.com wrote:


From: Gabor Grothendieck ggrothendi...@gmail.com
Subject: Re: [R] Problem with merging two zoo objects
To: Megh Dal megh700...@yahoo.com
Cc: r-h...@stat.math.ethz.ch
Date: Saturday, October 16, 2010, 12:11 AM
On Fri, Oct 15, 2010 at 2:20 PM, Megh
Dal megh700...@yahoo.com
wrote:
 Dear all, I have following 2 zoo objects. However when
I try to merge those 2 objects into one, nothing is coming
as intended. Please see below the objects as well as the
merged object:


 dat11
                      V2   V3   V4   V5
 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
 2010-10-15 13:49:51 73.7 73.7 73.7 73.7
 dat22
                      V2   V3   V4   V5
 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
 2010-10-15 12:41:03 73.7 73.7 73.7 73.7
 merge(dat11, dat22)
                    V2.dat11 V3.dat11
V4.dat11 V5.dat11 V2.dat22 V3.dat22 V4.dat22 V5.dat22
 2010-10-15 12:09:12       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 12:09:33       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:43:54       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:44:15       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:45:51       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:46:21       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:47:27       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:47:54       NA       NA      
NA       NA       NA       NA       NA      
NA
 2010-10-15 13:49:51       NA       NA      
NA       NA       NA       NA       NA      
NA
 Warning messages:
 1: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter
object length
 2: In MATCH(x, x) == seq_len(length(x)) :
  longer object length is not a multiple of shorter
object length

 If somebody points me whether I went wrong, it would
be really great.


If I try it then it works properly so there is likely
something wrong
with your dat11 and dat22 objects.  If you provide the
problem
reproducibly one might be able to say more.

 Lines1 - Date Time
V2   V3   V4   V5
+ 2010-10-15 13:43:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:44:15 73.8 73.8 73.8 73.8
+ 2010-10-15 13:45:51 73.8 73.8 73.8 73.8
+ 2010-10-15 13:46:21 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:27 73.8 73.8 73.8 73.8
+ 2010-10-15 13:47:54 73.8 73.8 73.8 73.8
+ 2010-10-15 13:49:51 73.7 73.7 73.7 73.7

 Lines2 - Date Time
V2   V3   V4   V5
+ 2010-10-15 12:09:12 74.0 74.0 74.0 74.0
+ 2010-10-15 12:09:33 73.9 73.9 73.9 73.9
+ 2010-10-15 12:20:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:30:36 74.0 74.0 74.0 74.0
+ 2010-10-15 12:41:03 73.7 73.7 73.7 73.7

 library(zoo)
 dat1 - read.zoo(textConnection(Lines1), header =
TRUE,
+ index = list(1, 2), FUN = function(d, t)
as.POSIXct(paste(d, t)))
Warning messages:
1: closing unused connection 8 (Lines2)
2: closing unused connection 7 (Lines1)
3: closing unused connection 5 (Lines2)
4: closing unused connection 4 (Lines1)
5: closing unused connection 3

Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Gabor Grothendieck
On Fri, Oct 15, 2010 at 3:22 PM, Megh Dal megh700...@yahoo.com wrote:
 Hi Gabor, please see the attached files which is in text format. I have 
 opened them on excel then, used clipboard to load them into R. Still really 
 unclear what to do.

 Also can you please elaborate this term index = list(1, 2), FUN = 
 function(d, t) as.POSIXct(paste(d, t)) in your previous file? In help, it is 
 given that:If FUN is specified then read.zoo calls FUN with the index as the 
 first argument. I really could not connect your syntax with help.

1. It works for me with the files you supplied. Note that you have
some duplicate times in your first file so I aggregated them using
only the last of any set of duplicates:
 library(zoo)
 dat11 - read.zoo(dal1.csv, aggregate = function(x) tail(x, 1),
+ sep = ,, header = TRUE, tz = , format = %m/%d/%Y %H:%M:%S)
 dat22 - read.zoo(dal2.csv,
+ sep = ,, header = TRUE, tz = , format =  %m/%d/%Y %H:%M:%S)
 m - merge(dat11, dat22)
 str(m)
‘zoo’ series from 2010-10-15 09:00:24 to 2010-10-15 13:49:51
  Data: num [1:361, 1:8] 74.3 74.3 74.3 74.2 74.2 ...
 - attr(*, dimnames)=List of 2
  ..$ : NULL
  ..$ : chr [1:8] data.open.dat11 data.high.dat11 data.low.dat11
data.close.dat11 ...
  Index:  POSIXct[1:361], format: 2010-10-15 09:00:24 2010-10-15
09:01:15 ...


  packageDescription(zoo)$Version
[1] 1.6-4

2. You seem to be using an old version of zoo.  With the latest
version of zoo on CRAN, 1.6-4, the index.column= documentation in
help(read.zoo) does document the list construction.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh

Thanks Gabor for pointing to my old version. However I got one more question
why the argument tz= is sitting there? As you are not passing any explicit
value for that, I am assuming it is redundant. Without any tz argument, I
got following:


head(read.zoo(file=f:/dat1.txt, header=T, sep=,, format = %m/%d/%Y
%H:%M:%S))
   data.open data.high data.low data.close
2010-10-15  73.7  73.7 73.7   73.7
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
Warning messages:
1: In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
2: In zoo(rval, x.index[i]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
 packageDescription(zoo)
Package: zoo
Version: 1.6-4
Date: 2010-07-09
Title: Z's ordered observations
Author: Achim Zeileis, Gabor Grothendieck, Felix Andrews
Maintainer: Achim Zeileis achim.zeil...@r-project.org
Description: An S3 class with methods for totally ordered indexed
observations. It is particularly aimed
   at irregular time series of numeric vectors/matrices and factors.
zoo's key design goals are
   independence of a particular index/date/time class and
consistency with ts and base R by
   providing methods to extend standard generics.
Depends: R (= 2.10.0), stats
Suggests: coda, chron, DAAG, fCalendar, fSeries, fts, its, lattice,
strucchange, timeDate, timeSeries,
   tis, tseries, xts
Imports: stats, utils, graphics, grDevices, lattice (= 0.18-1)
LazyLoad: yes
License: GPL-2


Clearly the format argument is not working properly, the time component is
missing. Why it is so?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-merging-two-zoo-objects-tp2997472p2997662.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Gabor Grothendieck
On Fri, Oct 15, 2010 at 4:27 PM, Megh megh700...@yahoo.com wrote:

 Thanks Gabor for pointing to my old version. However I got one more question
 why the argument tz= is sitting there? As you are not passing any explicit

It would otherwise assume Date class.

 str(read.zoo(file=dal1.csv, header=TRUE, sep=,, format = %m/%d/%Y 
 %H:%M:%S, aggregate = mean))
‘zoo’ series from 2010-10-15 to 2010-10-15
  Data: num [1, 1:4] 73.7 73.7 73.7 73.7
 - attr(*, dimnames)=List of 2
  ..$ : chr 2010-10-15
  ..$ : chr [1:4] data.open data.high data.low data.close
  Index: Class 'Date'  num 14897  


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Gabor Grothendieck
On Fri, Oct 15, 2010 at 9:56 PM, Megh Dal megh700...@yahoo.com wrote:
 However I have noticed a strange thing. Placing of tz =  matters here:

 head(read.zoo(f:/dat1.txt, sep = ,, header = TRUE, format =  %m/%d/%Y 
 %H:%M:%S), tz = )

Your tz argument has been passed as an argument of head.  You want it
as an argument of read.zoo .

           data.open data.high data.low data.close
 2010-10-15      73.7      73.7     73.7       73.7
 2010-10-15      73.8      73.8     73.8       73.8
 2010-10-15      73.8      73.8     73.8       73.8
 2010-10-15      73.8      73.8     73.8       73.8
 2010-10-15      73.8      73.8     73.8       73.8
 2010-10-15      73.8      73.8     73.8       73.8
 Warning messages:
 1: In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in 
 ‘order.by’ are not unique
 2: In zoo(rval, x.index[i]) :
  some methods for “zoo” objects do not work if the index entries in 
 ‘order.by’ are not unique

You are missing the aggregate= argument to read.zoo which is needed if
you have duplicate times in your input to tell it how to resolve them.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
However I have noticed a strange thing. Placing of tz =  matters here:

 head(read.zoo(f:/dat1.txt, sep = ,, header = TRUE, format =  %m/%d/%Y 
 %H:%M:%S), tz = )
   data.open data.high data.low data.close
2010-10-15  73.7  73.7 73.7   73.7
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
Warning messages:
1: In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique
2: In zoo(rval, x.index[i]) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique
 head(read.zoo(f:/dat1.txt, sep = ,, header = TRUE, tz = , format =  
 %m/%d/%Y %H:%M:%S))
data.open data.high data.low data.close
2010-10-15 09:00:24 74.35 74.3574.35  74.35
2010-10-15 09:01:15 74.30 74.3074.30  74.30
2010-10-15 09:01:21 74.35 74.3574.35  74.35
2010-10-15 09:01:27 74.20 74.2074.20  74.20
2010-10-15 09:01:30 74.25 74.2574.25  74.25
2010-10-15 09:01:36 74.25 74.2574.25  74.25
Warning message:
In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique

Is it a bug or a rule that for any function, placing of it's arguments matter?

Thanks,

--- On Sat, 10/16/10, Megh Dal megh700...@yahoo.com wrote:

 From: Megh Dal megh700...@yahoo.com
 Subject: Re: [R] Problem with merging two zoo objects
 To: Gabor Grothendieck ggrothendi...@gmail.com
 Cc: r-help@r-project.org
 Date: Saturday, October 16, 2010, 7:20 AM
 I dont know whether I am missing
 something or not:
 
  head(read.zoo(file=f:/dat1.txt, header=T, sep=,,
 format = %m/%d/%Y %H:%M:%S), tz=GMT)
            data.open
 data.high data.low data.close
 2010-10-15      73.7     
 73.7     73.7   
    73.7
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 Warning messages:
 1: In zoo(rval3, ix) :
   some methods for “zoo” objects do not work if
 the index entries in ‘order.by’ are not unique
 2: In zoo(rval, x.index[i]) :
   some methods for “zoo” objects do not work if
 the index entries in ‘order.by’ are not unique
  head(read.zoo(file=f:/dat1.txt, header=T, sep=,,
 format = %m/%d/%Y %H:%M:%S))
            data.open
 data.high data.low data.close
 2010-10-15      73.7     
 73.7     73.7   
    73.7
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 2010-10-15      73.8     
 73.8     73.8   
    73.8
 Warning messages:
 1: In zoo(rval3, ix) :
   some methods for “zoo” objects do not work if
 the index entries in ‘order.by’ are not unique
 2: In zoo(rval, x.index[i]) :
   some methods for “zoo” objects do not work if
 the index entries in ‘order.by’ are not unique
 
 In either case, I am missing the time component. Where I
 am going wrong?
 
 Thanks,
 
 
 --- On Sat, 10/16/10, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:
 
  From: Gabor Grothendieck ggrothendi...@gmail.com
  Subject: Re: [R] Problem with merging two zoo objects
  To: Megh megh700...@yahoo.com
  Cc: r-help@r-project.org
  Date: Saturday, October 16, 2010, 2:33 AM
  On Fri, Oct 15, 2010 at 4:27 PM, Megh
  megh700...@yahoo.com
  wrote:
  
   Thanks Gabor for pointing to my old version.
 However I
  got one more question
   why the argument tz= is sitting there? As you
 are
  not passing any explicit
  
  It would otherwise assume Date class.
  
   str(read.zoo(file=dal1.csv, header=TRUE,
 sep=,,
  format = %m/%d/%Y %H:%M:%S, aggregate = mean))
  ‘zoo’ series from 2010-10-15 to 2010-10-15
    Data: num [1, 1:4] 73.7 73.7 73.7 73.7
   - attr(*, dimnames)=List of 2
    ..$ : chr 2010-10-15
    ..$ : chr [1:4] data.open data.high data.low
  data.close
    Index: Class 'Date'  num 14897 
 
 
  
  
  -- 
  Statistics  Software Consulting
  GKX Group, GKX Associates Inc.
  tel: 1-877-GKX-GROUP
  email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem with merging two zoo objects

2010-10-15 Thread Megh Dal
I dont know whether I am missing something or not:

 head(read.zoo(file=f:/dat1.txt, header=T, sep=,, format = %m/%d/%Y 
 %H:%M:%S), tz=GMT)
   data.open data.high data.low data.close
2010-10-15  73.7  73.7 73.7   73.7
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
Warning messages:
1: In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique
2: In zoo(rval, x.index[i]) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique
 head(read.zoo(file=f:/dat1.txt, header=T, sep=,, format = %m/%d/%Y 
 %H:%M:%S))
   data.open data.high data.low data.close
2010-10-15  73.7  73.7 73.7   73.7
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
2010-10-15  73.8  73.8 73.8   73.8
Warning messages:
1: In zoo(rval3, ix) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique
2: In zoo(rval, x.index[i]) :
  some methods for “zoo” objects do not work if the index entries in ‘order.by’ 
are not unique

In either case, I am missing the time component. Where I am going wrong?

Thanks,


--- On Sat, 10/16/10, Gabor Grothendieck ggrothendi...@gmail.com wrote:

 From: Gabor Grothendieck ggrothendi...@gmail.com
 Subject: Re: [R] Problem with merging two zoo objects
 To: Megh megh700...@yahoo.com
 Cc: r-help@r-project.org
 Date: Saturday, October 16, 2010, 2:33 AM
 On Fri, Oct 15, 2010 at 4:27 PM, Megh
 megh700...@yahoo.com
 wrote:
 
  Thanks Gabor for pointing to my old version. However I
 got one more question
  why the argument tz= is sitting there? As you are
 not passing any explicit
 
 It would otherwise assume Date class.
 
  str(read.zoo(file=dal1.csv, header=TRUE, sep=,,
 format = %m/%d/%Y %H:%M:%S, aggregate = mean))
 ‘zoo’ series from 2010-10-15 to 2010-10-15
   Data: num [1, 1:4] 73.7 73.7 73.7 73.7
  - attr(*, dimnames)=List of 2
   ..$ : chr 2010-10-15
   ..$ : chr [1:4] data.open data.high data.low
 data.close
   Index: Class 'Date'  num 14897 
 
 
 
 -- 
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.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
and provide commented, minimal, self-contained, reproducible code.