[R] is.na with lists....

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Sat Jul 2 20:03:43 CEST 2022


Dear memebers,
                            I have list of stock data OHLCData for 500 stocks, 15 of whom are NA's. The following is the code:

require(quantmod)
getOHLCData <- function(NSESym) {
  OHLCData1 <- list()
  for(i in 1:500){
    OHLCData1[[i]] <- tryCatch(getSymbols(NSESym[i], auto.assign=FALSE),
                          error = function (e) {print(i); return(NA)})

  }
  return(OHLCData1)
}

 OHLCData <- getOHLCData(NSESym)

however, when I check for is.na, I get the following:

length(OHLCData)
[1] 500
> length(is.na(OHLCData))
[1] 500

length(is.na(OHLCData)) should return 15. Whats going wrong? I assume is.na returns TRUE if there is an NA.

Yours sincerely,
AKSHAY M KULKARNI

	[[alternative HTML version deleted]]



More information about the R-help mailing list