Skip to content

rmoving dates from an xts object...

5 messages · Bert Gunter, Gabor Grothendieck, akshay kulkarni

#
Dear members,
                         I have OHLC data of 500 stocks: OHLCData and dates. These are of xts object. I want to do the following:


  1.  I want to remove a contiguous set of dates from the xts object. for example, I want to remove data from the OHLC data from "2022-20-7"
  2.   to "2018-2-2", continuously.
  3.

       2. I want to remove a set of dates, which are not contiguous.

Any idea on how to accomplish it? I can write an intricate for loop, but any other method? Does an xts object behave like an atomic vector : OHLCData[[i]][-dates[[i]]] ?

Many thanks in advance....

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
#
Time to do your homework:

https://rpubs.com/odenipinedo/manipulating-time-series-data-with-xts-and-zoo-in-R

Bert
On Sun, Jul 10, 2022, 6:42 PM akshay kulkarni <akshay_e4 at hotmail.com> wrote:

            

  
  
#
Look at the examples at the end of ?xts for more info.

  library(quantmod)
  getSymbols("AAPL")

  class(AAPL)
  ## [1] "xts" "zoo"

  range(time(AAPL))
  ## [1] "2007-01-03" "2022-07-08"

  # everything up to indicated date
  a1 <- AAPL["/2018-02-01"]

  # remove non consecutive dates
  d <- as.Date(c("2022-07-01", "2022-07-06")) # dates to remove
  a2 <- AAPL[ ! time(AAPL) %in% d ]
On Sun, Jul 10, 2022 at 11:42 AM akshay kulkarni <akshay_e4 at hotmail.com> wrote:

  
    
1 day later
#
dear Bert,
                 Went through it........thanks a lot...

Yours sincerely,
AKSHAY M KULKARNI
#
dear Gabor,
                   THanks a lot....

Yours sincerely,
AKSHAYM KULKARNI