[R] Odp: if ( expr )
Petr PIKAL
petr.pikal at precheza.cz
Tue Nov 20 10:32:31 CET 2007
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 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.
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 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.
More information about the R-help
mailing list