Skip to content
Back to formatted view

Raw Message

Message-ID: <CAPPM_gQxxNMckWnKytmv5nudsRxgae=oyoU58uJbTo4vKTZ8Sw@mail.gmail.com>
Date: 2012-05-29T19:17:15Z
From: Joshua Ulrich
Subject: Converting to XTS loses data.frame structure
In-Reply-To: <3188565B-EBE6-4952-B159-8B51FED16E95@ucla.edu>

On Tue, May 29, 2012 at 2:11 PM, Noah Silverman <noahsilverman at ucla.edu> wrote:
> Hello,
>
> I noticed something odd when working with data frames and xts objects.
>
> If I read in a CSV file, R creates a nice data.frame. ?This works well.
>
> If I then convert to an XTS object, I see that all the values in the data are now quoted. ?My data is a mix of numeric and character. ?This is usually seen when converting a data.frame to a matrix, as R will treat all the data as the same class. (character)
>
> How can I ensure that R creates an XTS object that is still a data.frame so that all the data are the correct type??
>
You can't.  xts/zoo objects are a matrix with an index attribute.
Since you can't mix types in a matrix, you can't mix types in an
xts/zoo object.  That said, part of the xts Google Summer of Code
project is to create an xts-like object that allows mixed types.

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com