[R] NULL object, R programming
Spencer Graves
spencer.graves at pdf.com
Fri Feb 28 06:15:06 CET 2003
When you set the second attribute of the list to NULL, it actually
eliminated that attribute, so the length(a) went from 3 to 2. If you
don't like that, try the following:
a <- list(a=3, b=4, c=5)
a[["b"]] <- NULL
You can still refer to the attributes of the list via a[["a"]],
a[["c"]]], a$a, a$b, etc., and get what you expect even though though
the length of the list has been reduced.
Spencer Graves
Makram Talih wrote:
> Dear R users,
>
> I get the following (I think puzzling) result when doing the following:
>
>
>>a <- list(3,4,5)
>>a[[2]] <- NULL
>>a
>
> [[1]]
> [1] 3
>
> [[2]]
> [1] 5
>
> I would have expected the result to be:
>
> [[1]]
> [1] 3
>
> [[2]]
> NULL
>
> [[3]]
> [1] 4
>
> as in the outcome of:
>
>
>>list(3, NULL, 4)
>
>
> Is this a desired effect? If so, could it be built in a 'help(NULL)' file?
>
> If you think it is relevant, I am using the following R version:
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 1
> minor 6.2
> year 2003
> month 01
> day 10
> language R
>
>
> Many thanks for any clarifications regarding this!
>
> Regards,
>
> Makram Talih
> Yale University
> Statistics
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
More information about the R-help
mailing list