[R] How to test if something doesn't exist
Doran, Harold
HDoran at air.org
Wed May 22 21:13:44 CEST 2013
Joe
Testing is something _exists_ is different than testing if something has what you are referring to as a valid value. Here is one way to do what I think you are doing versus testing if something exists
validVal <- function(x, val){
if (!is.numeric(x)) stop('Not a numeric variable')
else x > val
}
x <- 1
y <- 'foo'
validVal(x, 0)
validVal(x, 1)
validVal(y, 0)
exists('x')
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Joseph Trubisz
Sent: Wednesday, May 22, 2013 2:09 PM
To: r-help at r-project.org
Subject: [R] How to test if something doesn't exist
Couldn't exactly explain the subject, so here's the example:
idx<-which(blah[,1]=="xyz")
idx
integer(0)
How do I test that idx has a valid value (namely, > 0)?
TiA,
Joe
______________________________________________
R-help at r-project.org mailing list
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.
More information about the R-help
mailing list