It's supposed to match the length. Perhaps you meant to use which(is.na())? On Sat, Jul 2, 2022, 14:04 akshay kulkarni <akshay_e4 at hotmail.com> wrote:> 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]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
People often use sum() to count how many boolean values are true, not length). Sent from the all new AOL app for Android On Sat, Jul 2, 2022 at 2:14 PM, Andrew Simmons<akwsimmo at gmail.com> wrote: It's supposed to match the length. Perhaps you meant to use which(is.na())? On Sat, Jul 2, 2022, 14:04 akshay kulkarni <akshay_e4 at hotmail.com> wrote:> 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]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
Dear Andrew,
It's working! Thanks... I thought the following
> length(is.na(c(1,2,3,NA)))
would return
[1] 1
But got to know the difference ... thanks.
Yours sincerely,
AKSHAY M KULKARNI
________________________________
From: Andrew Simmons <akwsimmo at gmail.com>
Sent: Saturday, July 2, 2022 11:36 PM
To: akshay kulkarni <akshay_e4 at hotmail.com>
Cc: R help Mailing list <r-help at r-project.org>
Subject: Re: [R] is.na with lists....
It's supposed to match the length. Perhaps you meant to use
which(is.na<http://is.na>())?
On Sat, Jul 2, 2022, 14:04 akshay kulkarni <akshay_e4 at
hotmail.com<mailto:akshay_e4 at hotmail.com>> wrote:
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<http://is.na>, I get the following:
length(OHLCData)
[1] 500> length(is.na<http://is.na>(OHLCData))
[1] 500
length(is.na<http://is.na>(OHLCData)) should return 15. Whats going wrong?
I assume is.na<http://is.na> returns TRUE if there is an NA.
Yours sincerely,
AKSHAY M KULKARNI
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list -- To
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]