[R-SIG-Finance] xts - Is there a quick and dirty way to manually edit an xts object ?

Dirk Eddelbuettel edd at debian.org
Sun May 16 20:36:39 CEST 2010


On 16 May 2010 at 20:19, me at censix.com wrote:
| Hi to the list. I am looking for a fast way to manually edit an xts object
| in R, i.e. by using the de(..) function. See example.
| 
| require(xts)
| require(quantmod)
| getSymbols("YHOO")
| is.xts(YHOO) #TRUE
| 
| edited<-de(YHOO) # Does not work
| edited<-de(as.matrix(YHOO)) # Does work for the values, but the date index
| is not editable. Is there a (quick) way to edit the full xts object ?

Tough because 

   R> head(index(YHOO))
   [1] "2007-01-03" "2007-01-04" "2007-01-05" "2007-01-08" "2007-01-09" "2007-01-10"
   R> head(as.numeric(index(YHOO)))
   [1] 13516 13517 13518 13521 13522 13523
   R> 

Dates are integers; intra-daily POSIXct is floats.  Not really stuff you'd
want to edit.  You your problem is that 'what you see is NOT what you got' --
consider the first date which is printed (ie format()'ed) as 2007-01-03 but
stored as 13516.

I think you may want to write a helper function instead:

  decompose an xts in payload and index
  edit either or both
  stick it back together

and iterate til you are happy.

-- 
  Regards, Dirk



More information about the R-SIG-Finance mailing list