Adrian Alexa <[EMAIL PROTECTED]> writes:
> 
> I have observed that is.na() behaves strange on some lists. Here is a
> simple example:
> 
> 
> > a = list(list('asd'))
> > a
> [[1]]
> [[1]][[1]]
> [1] "asd"
> 
> 
> > for(i in 1:5)
> + print(is.na(a))
> [1] TRUE
> [1] FALSE
> [1] TRUE
> [1] TRUE
> [1] TRUE
> >
> 
> [...snip...]
> 
> In my view this seems to be a bug. If is not, can somebody explain me what is
> really happening and how can I overcome this behavior?

This looks like a bug to me.  As far as a workaround goes you
could try this:


is.na <- function(x)
   if (length(x) == 0) {
      mode(x) <- "logical"
      x
   } else if (inherits(x, "list")) {
      lapply(x, function(i) if (is.atomic(x)) base::is.na(x) else FALSE)
   } else 
      base::is.na(x)

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to