[R] Strange behavior of is.na() on lists
Adrian Alexa
adrian.alexa at gmail.com
Sat Sep 25 18:26:11 CEST 2004
Hello R-users,
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
>
> for(i in 1:10)
+ print(as.integer(is.na(a)))
[1] 0
[1] 10
[1] 1
[1] 0
[1] 140897024
[1] 134567568
[1] 1
[1] 1953720684
[1] 145687400
[1] 1886352499
>
This is a very strange thing. The result is similar when applying
is.na() on more
complex lists: list(list(list(.....)). A concrete example where I
found this behavior is
the following list:
> str(as.list(hgu95av2GO)[1:5])
List of 5
$ 1114_at :List of 6
..$ GO:0005125:List of 3
.. ..$ GOID : chr "GO:0005125"
.. ..$ Evidence: chr "IEA"
.. ..$ Ontology: chr "MF"
...................................
..$ GO:0040007:List of 3
.. ..$ GOID : chr "GO:0040007"
.. ..$ Evidence: chr "IEA"
.. ..$ Ontology: chr "BP"
$ 36421_at : logi NA
$ 329_s_at :List of 5
..$ GO:0005198:List of 3
.. ..$ GOID : chr "GO:0005198"
.. ..$ Evidence: chr "TAS"
.. ..$ Ontology: chr "MF"
...................................
..$ GO:0005634:List of 3
.. ..$ GOID : chr "GO:0005634"
.. ..$ Evidence: chr "TAS"
.. ..$ Ontology: chr "CC"
$ 34687_at :List of 3
..$ GO:0016020:List of 3
.. ..$ GOID : chr "GO:0016020"
.. ..$ Evidence: chr "IEA"
.. ..$ Ontology: chr "CC"
...................................
Is this behavior normal? I should mention that I try the examples on
different versions of R:
1 R 1.9.1 Debian Sarge
2 R 2.0.0 beta Debian Sarge
3 R 1.9.1 Windows
4 R 1.8.1 SunOS
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?
Many thanks,
Adrian
--
Adrian Alexa
Max-Planck-Institut fuer Informatik
Stuhlsatzenhausweg 85 Room 514
66123 Saarbruecken, Germany
More information about the R-help
mailing list