[R] list of lists, is this element empty

Boris Steipe boris.steipe at utoronto.ca
Sat Dec 20 21:41:14 CET 2014


Thanks. This is what I was referring to:

x <- rep(NA, 3)
is.na(x)
[1] TRUE TRUE TRUE

if (is.na(x)) {print("True")}
[1] "True"
Warning message:
In if (is.na(x)) { :
  the condition has length > 1 and only the first element will be used

You are of course right - the warning is generated by if(), not by is.na() and the reason for the warning is that is.na() returns a vector if applied to a vector. I should have been more clear.

Cheers,
B.



On Dec 20, 2014, at 3:29 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

> This may be out of context, but on the face of it, this claim is wrong:
> 
> On 20/12/2014, 1:57 PM, Boris Steipe wrote:
> "Moreover is.na() behaves differently when evaluated on its own, or as
> the condition of an if() statement."
> 
> The conditions in an if() statement are not evaluated in special
> conditions at all.  The only way you'll get a different value is if the
> argument to is.na() does tricky stuff like looking at the evaluation stack.
> 
> Duncan Murdoch



More information about the R-help mailing list