[R-SIG-Finance] insert element in IBrokers/XTS time series?
Sean Carmody
seancarmody at gmail.com
Mon Jul 6 07:52:01 CEST 2009
Here's a more elegant approach that should not generate the error message:
xts(rbind(coredata(myhist), rep(NA,dim(myhist)[2])),
order.by=c(index(myhist), as.Date("2009-01-01")))
Note that if class(index(myhist)) is not type "Date" you will need to
replace as.Date with the appropriate constructor, e.g. as.POSIXct or
as.chron.
Regards,
Sean.
On Mon, Jul 6, 2009 at 3:09 PM, Michael<comtech.usa at gmail.com> wrote:
> still not working...
>
> On Sat, Jul 4, 2009 at 2:10 PM, Sean Carmody<seancarmody at gmail.com> wrote:
>> Sorry, try this
>>
>> rbind(myhist, xts(data.frame(NA,NA,NA,NA,NA,NA),
>> order.by=as.Date("2009-08-01")))
>>
>> also, check class(time(myhist)) and if it is not "Date" you may need
>> to replace as.Date with the appropriate constructor for your time
>> class.
>>
>> Sean.
>>
>> On Sun, Jul 5, 2009 at 2:47 AM, Michael<comtech.usa at gmail.com> wrote:
>>> I got an error:
>>>
>>> Error in xts(data.frame(rep(NA, 6), order.by = as.Date("2009-08-01"))) :
>>> order.by requires an appropriate time-based object
>>>
>>> On Sat, Jul 4, 2009 at 2:26 AM, Sean Carmody<seancarmody at gmail.com> wrote:
>>>> Eliminating a row is straightforward, e.g.
>>>>
>>>> myhist[time(myhist) != as.Date("2009-06-29"),]
>>>>
>>>> will return everything except the entry for 2009-06-29.
>>>>
>>>> Adding a row is, I believe, a bit more fiddly. You can use
>>>>
>>>> rbind(myhist, xts(data.frame(rep(NA,6), order.by=as.Date("2009-08-01")))
>>>>
>>>> although this will give a warning message about column names
>>>> differing. If you have an additional xts with the same column names,
>>>> you can simply use merge()
>>>>
>>>> Sean.
>>>>
>>>> On Sat, Jul 4, 2009 at 10:01 AM, Michael<comtech.usa at gmail.com> wrote:
>>>>> Hi all,
>>>>>
>>>>> Let's say I have the following timeseres in IBrokers and XTS:
>>>>>
>>>>> 2009-06-25 18038 18350 18011 18327 5396 18183
>>>>> 2009-06-26 18420 18708 18331 18515 7367 18499
>>>>> 2009-06-29 18546 18688 18423 18577 28728 18555
>>>>> 2009-07-03 17951 18198 17866 18149 38019 18059
>>>>>
>>>>> I want to add a few more rows, indexed by
>>>>>
>>>>> "2009-06-30", "2009-07-01", "2009-07-02", and using NA's,
>>>>>
>>>>> I did the following:
>>>>>
>>>>> myhist["2009-07-01",]=c(NA, NA, NA, NA, NA, NA, NA, NA)
>>>>>
>>>>> But it didn't really work.
>>>>>
>>>>> What's the good way to insert missing points in time series?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> _______________________________________________
>>>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>>>> -- Subscriber-posting only.
>>>>> -- If you want to post, subscribe first.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Sean Carmody
>>>>
>>>> The Stubborn Mule
>>>> http://www.stubbornmule.net
>>>> http://twitter.com/seancarmody
>>>>
>>>
>>
>>
>>
>> --
>> Sean Carmody
>>
>> The Stubborn Mule
>> http://www.stubbornmule.net
>> http://twitter.com/seancarmody
>>
>
--
Sean Carmody
The Stubborn Mule
http://www.stubbornmule.net
http://twitter.com/seancarmody
More information about the R-SIG-Finance
mailing list