How to append new value to xts object without creating a new one

I have an xts object, for example

ts=xts(seq(10),seq(Sys.Date(),Sys.Date()+10,length.out=10))

and need to add a new point, for example

(Sys.Date()+11, 11)

I have tried

ts[Sys.Date()+11] <- 11

but it doesnt work. I would prefer to avoid creating a new xts object. Is there an elegant way to do this.

Answers


You can use c or rbind on an xts object to append row-wise:

c(ts, xts(11, Sys.Date()+11))

EDIT :

Note that this produces a warning mismatched types: converting objects to numeric. To remove the warning, first coerce the value to numeric, e.g:

c(ts, xts(as.integer(11), Sys.Date()+11))

           [,1]
2011-12-01    1
2011-12-02    2
2011-12-03    3
2011-12-04    4
2011-12-05    5
2011-12-06    6
2011-12-07    7
2011-12-08    8
2011-12-09    9
2011-12-11   10
2011-12-12   11

Need Your Help

Java profiling - How reliable are the values it gives?

java text markup

I am working on a simple text markup Java Library which should be, amongst other requirements, fast.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.