Hi there, (sorry Martin, ich habe den falschen Empfaenger erwischt :-( ) Is there a function in the base package or elsewhere which returns TRUE and not NA, even if NA is involved: (I did not find in the help system :-( ) if ( x==something & !is.na(something)) or if ( x==something & !is.na(x==something)) If "something" is complicated, a function would be handy. Thanks --christian Dr.sc.math.Christian W. Hoffmann Mathematics and Statistical Computing Landscape Dynamics and Spatial Development Swiss Federal Research Institute WSL Zuercherstrasse 111 CH-8903 Birmensdorf, Switzerland phone: ++41-1-739 22 77 fax: ++41-1-739 22 15 e-mail: christian.hoffmann at wsl.ch www: http://www.wsl.ch/staff/christian.hoffmann/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 4 Sep 2002, Christian Hoffmann wrote:> Hi there, (sorry Martin, ich habe den falschen Empfaenger erwischt :-( ) > > Is there a function in the base package or elsewhere which returns TRUE and > not NA, even if NA is involved: (I did not find in the help system :-( ) > > if ( x==something & !is.na(something)) > > or > > if ( x==something & !is.na(x==something)) >x %in% something is TRUE if x is an element of something and FALSE otherwise, so your first example could be if (x %in% something) -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I sometimes use identical(T, boolean.expression) for this purpose, e.g.:
> identical(T,3*4==12)
[1] TRUE
> identical(T,3*4==11)
[1] FALSE
> identical(T,3*NA==11)
[1] FALSE
However, this is not ideal because if your objects have names, identical
will return false if the names don't match:
> 3*4==c(a=12)
a
TRUE
> identical(T,3*4==c(a=12))
[1] FALSE
> identical(c(a=TRUE),3*4==c(a=12))
[1] TRUE
You can get around this problem by wrapping the expression with as.logical
(to strip names), but it's starting to get cumbersome (though the
expression still only occurs once):
> identical(TRUE,as.logical(3*4==c(a=12)))
[1] TRUE
>
-- Tony Plate
At 10:29 AM 9/4/2002 +0200, Christian Hoffmann wrote:>Hi there, (sorry Martin, ich habe den falschen Empfaenger erwischt :-( )
>
>Is there a function in the base package or elsewhere which returns TRUE
>and not NA, even if NA is involved: (I did not find in the help system :-(
)
>
>if ( x==something & !is.na(something))
>
>or
>
>if ( x==something & !is.na(x==something))
>
>If "something" is complicated, a function would be handy.
>
>Thanks
>--christian
>
>
>Dr.sc.math.Christian W. Hoffmann
>Mathematics and Statistical Computing
>Landscape Dynamics and Spatial Development
>Swiss Federal Research Institute WSL
>Zuercherstrasse 111
>CH-8903 Birmensdorf, Switzerland
>phone: ++41-1-739 22 77 fax: ++41-1-739 22 15
>e-mail: christian.hoffmann at wsl.ch
>www: http://www.wsl.ch/staff/christian.hoffmann/
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Thomas, hi Tony Thanks for the hint! My motivation behind the question was to install all recommended packages: install.packages(CRAN.packages()[CRAN.packages()[,3] %in% "recommended",1]) --christian At 07:46 04.09.2002 -0700, you wrote:>On Wed, 4 Sep 2002, Christian Hoffmann wrote: > > > Hi there, (sorry Martin, ich habe den falschen Empfaenger erwischt :-( ) > > > > Is there a function in the base package or elsewhere which returns TRUE and > > not NA, even if NA is involved: (I did not find in the help system :-( ) > > > > if ( x==something & !is.na(something)) > > > > or > > > > if ( x==something & !is.na(x==something)) > > > >x %in% something >is TRUE if x is an element of something and FALSE otherwise, so your first >example could be > if (x %in% something) > > -thomasDr.sc.math.Christian W. Hoffmann Mathematics and Statistical Computing Landscape Dynamics and Spatial Development Swiss Federal Research Institute WSL Zuercherstrasse 111 CH-8903 Birmensdorf, Switzerland phone: ++41-1-739 22 77 fax: ++41-1-739 22 15 e-mail: christian.hoffmann at wsl.ch www: http://www.wsl.ch/staff/christian.hoffmann/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._