[R] merge xts objects with different data types ?
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Fri Sep 4 03:21:38 CEST 2015
The root of your problems lie in your assumption that xts variables act like data frames. Instead they are matrices with an index attribute. All values in a matrix must be of the same storage mode.
You might want to investigate the data.table package. It is not a time series object but you can still handle time series operations and you can have any type of data.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
On September 3, 2015 5:40:36 PM PDT, ce <zadig_1 at excite.com> wrote:
>
>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
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.
More information about the R-help
mailing list