[R] XTS : merge.xts seems to have problem with character vectors

rivercode aquanyc at gmail.com
Tue Jan 4 19:42:45 CET 2011


Hi,

Please can you tell me what I am doing wrong.  When trying to merge two xts
objects, one of which has multiple character vectors for columns...I am just
getting NAs.

> str(t)
 POSIXct[1:1], format: "2011-01-04 11:45:37"

> y2 = xts(matrix(c(letters[1:10]),5), order.by=as.POSIXct(c(t + 1:5)))
> names(y2) = c(1,2)
> y2
                    1   2  
2011-01-04 11:45:38 "a" "f"
2011-01-04 11:45:39 "b" "g"
2011-01-04 11:45:40 "c" "h"
2011-01-04 11:45:41 "d" "i"
2011-01-04 11:45:42 "e" "j"

> y1 = xts(c(1:5), order.by=as.POSIXct(c(t + 1:5)))
> y1
                    [,1]
2011-01-04 11:45:38    1
2011-01-04 11:45:39    2
2011-01-04 11:45:40    3
2011-01-04 11:45:41    4
2011-01-04 11:45:42    5

> merge(y1, y2)
                    y1 X1 X2
2011-01-04 11:45:38  1 NA NA
2011-01-04 11:45:39  2 NA NA
2011-01-04 11:45:40  3 NA NA
2011-01-04 11:45:41  4 NA NA
2011-01-04 11:45:42  5 NA NA

Warning message:
In merge.xts(y1, y2) : NAs introduced by coercion

Why do I lose the character columns ?

Cheers,
Chris
-- 
View this message in context: http://r.789695.n4.nabble.com/XTS-merge-xts-seems-to-have-problem-with-character-vectors-tp3174125p3174125.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list