[R] is.null doesn't work

Douglas Bates bates at stat.wisc.edu
Fri Jul 13 01:44:04 CEST 2007


On 7/12/07, Atte Tenkanen <attenka at utu.fi> wrote:

> Seems to work, if I unlist the argument at first ;-)

> Atte

> > Hi,

> > What's wrong here?:

> > > v=c(`-`,`+`,1,`^`,`^`,NA,NA,"X",9,"X",2)
> > > i2=16
> > > v[i2]
> > [[1]]
> > NULL

> > > is.null(v[i2])
> > [1] FALSE

> > Is it a bug or have I misunderstood something?

v[2] is a list with a single element which happens to be NULL.
v[[2]], on the other hand, is NULL.

A subset of a list, obtained with "[", is a list.  An element of a
list, obtained with "[[", is the native type of that element.

> > Atte Tenkanen
> > University of Turku, Finland
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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