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')
"
if(any(blah=="xyz")) blah else as.numeric(factor(blah))
#[1] 1 2 3 4 5
A.K.
----- Original Message -----
From: Joseph Trubisz
To: arun
Cc:
Sent: Wednesday, May 22, 2013 2:37 PM
Subject: Re: [R] How to test if something doesn't exist
OK...got it...thanks
Joe
On M
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
To: r-help@r-p
3 matches
Mail list logo