0
votes

I actually have an identical question as to topic:

Keeping Character Types/Names in xts object in R

However, the question doesn't seem to have been resolved, and whether or not the original poster was able to solve the issue is unknown so I thought I should ask it again and hopefully obtain an answer.

I am working with a data table and I would like to convert this data table to an xts object. In my code I use the function as.xts() to convert a data table object to an xts object, and when this happens the xts package drops all non-numeric columns and turns the data table into an xts object/matrix.

Now, there is a column in the data table object which is filled with names, and I would like to prevent xts from dropping this column when I convert the data table to an xts object. Is this possible?

1
In that post the OP just wanted to retain the information. He did not intend to use the names. Similarly, if you want to retain the names, you can specify them in attributes of the xts object. xts_obj<-xts(x=some_mat,order_by=TIME, attr_name=dt$name) . You can go through the chat discussion on that thread and see if it serves your purpose.tushaR
I too do not wish to use the names in the xts object, I just want them there so it's easier to keep track of things. However, when you use the as.xts() function then it will automatically drop all columns with non-numeric data types in them, so I'm looking for a way to keep them. I should note that I am looking to specifically use the as.xts() function since it is much faster at converting objects compared to the xts() function, and since I am working with extremely large objects I basically need all the speed I can getNotsurewhatImdoing
Yes, but although xts() may work it does seem to be much, much slower. I ran it over a smaller dataset than what I'm currently using and it took a much longer time to perform the conversion compared to as.xts(), I'm going to keep playing around with it a bit more and hope I can knock the time down more thoughNotsurewhatImdoing

1 Answers

1
votes

I hate to say it, but the answer is no. An xts object is essentially a matrix which has been indexed by dates. The closest thing you'll have to words are the column names.