[R] merge xts objects with different data types ?
ce
zadig_1 at excite.com
Fri Sep 4 02:40:36 CEST 2015
Hello
Let's say some questions about merging xts variables :
a<- xts("abc", Sys.Date())
b <- xts("def", Sys.Date())
c <- xts(1, Sys.Date())
> merge(a,b)
a b
2015-09-03 "abc" "def"
> merge(a,b,c)
a b c
2015-09-03 NA NA 1
Warning messages:
1: In merge.xts(a, b, c) : NAs introduced by coercion
2: In merge.xts(a, b, c) : NAs introduced by coercion
3: In merge.xts(a, b, c) : NAs introduced by coercion
4: In merge.xts(a, b, c) : NAs introduced by coercion
How I can merge a, b ,c correctly ? Another example is with Binary variables :
> e<- xts(TRUE, Sys.Date())
> e
[,1]
2015-09-03 TRUE
> merge(e,b)
e b
2015-09-03 1 NA
Warning message:
In merge.xts(e, b) : NAs introduced by coercion
My second question is how I can convert an xts object to factor :
> d <- merge(a,b)
> d
a b
2015-09-03 "abc" "def"
> factor(d, levels = c("abc","def"))
a b
abc def
Levels: abc def
Date disappears here?
Thanks for your help
ce
More information about the R-help
mailing list