Hello, I've searched the list but haven't found anything really applicable to my question. Any advice would be super. I'm working on a snippet of R code and I have a function with a prototype like this: foo <- function( x, ... ){ if( is.na(x)[1] ) {etc...} } Where x is typically a vector of bools. At times, however, x can be NA, and yet at other super rare times x can be the result of this type of comparison: c(4,5,13,2,3,4,5,7) == numeric(0) which produces logical(0). When this is the case, if( is.na(x)[1] ) isn't happy. I'm trying to create a condition to my "if" statement inside foo that only is true when x is NA but that doesn't die when its a logical(0). Any suggestions on how best to approach this? As always, thanks a bunch, Greg
Hi r-help-bounces at r-project.org napsal dne 20.11.2007 10:03:53:> > Hello, > > I've searched the list but haven't found anything really applicable tomy> question. Any advice would be super. > > I'm working on a snippet of R code and I have a function with aprototype> like this: > > foo <- function( x, ... ){ > if( is.na(x)[1] ) {etc...} > } > > Where x is typically a vector of bools. > > At times, however, x can be NA, and yet at other super rare times x canbe> the result of this type of comparison: > > c(4,5,13,2,3,4,5,7) == numeric(0) > > which produces logical(0). When this is the case, if( is.na(x)[1] )isn't> happy.Check the length. In case of numeric(0) or logical(0) the length is 0 which you can use for testing. Regards Petr> > I'm trying to create a condition to my "if" statement inside foo thatonly> is true when x is NA but that doesn't die when its a logical(0). > > Any suggestions on how best to approach this? > > As always, thanks a bunch, > > Greg > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
How about if (is.na(c(x,1))[1]) ....... --- Gregory Wall <gdwall at ucdavis.edu> wrote:> > Hello, > > I've searched the list but haven't found anything > really applicable to my > question. Any advice would be super. > > I'm working on a snippet of R code and I have a > function with a prototype > like this: > > foo <- function( x, ... ){ > if( is.na(x)[1] ) {etc...} > } > > Where x is typically a vector of bools. > > At times, however, x can be NA, and yet at other > super rare times x can be > the result of this type of comparison: > > c(4,5,13,2,3,4,5,7) == numeric(0) > > which produces logical(0). When this is the case, > if( is.na(x)[1] ) isn't > happy. > > I'm trying to create a condition to my "if" > statement inside foo that only > is true when x is NA but that doesn't die when its a > logical(0). > > Any suggestions on how best to approach this? > > As always, thanks a bunch, > > Greg > > ______________________________________________ > 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. >
Possibly Parallel Threads
- [Patch][RFC] Super Page Patch
- Calling substitute(expr, list(a=1)) when expr <- expression(a+b+c)
- .doTrace problem with eval.parent(substitute(expr)) vs. lazy evaluation of expr
- [Bug 3158] New: ssh-copy-id raises "expr: syntax error" when double-hyphen is passed ("--")
- [LLVMdev] [LLVMDev] [Modeling] About the structure of my allocator