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
How to test if something doesn't exist
3 messages · Joseph Trubisz, arun, Doran, Harold
Hi Joe,
Not sure about your expected result
?blah<- paste0("x",1:5)
?which(blah=="xyz")
#integer(0)
blah=="xyz"
#[1] FALSE FALSE FALSE FALSE FALSE
?any(blah=="xyz")
#[1] FALSE
?sum(blah=="xyz")
#[1] 0
sum(blah=="x1")
#[1] 1
A.K.
----- Original Message -----
From: Joseph Trubisz <jtrubisz at me.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, May 22, 2013 2:08 PM
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.
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.