[Rd] double bracket stripping names
Hadley Wickham
h.wickham at gmail.com
Tue Feb 26 18:21:33 CET 2013
> Yes, as Brian said. And this makes sense: the names are a property of the
> container, not a property of the contents. Using single brackets creates a
> new container with a subset of the elements. Using double brackets extracts
> an element.
>
> The fact that there's no way to hold a number other than in a length one
> container means that the results are both length one containers, but
> conceptually there's a difference between subsetting and extracting. Perhaps
> at some distant date in the future scalar numbers will be possible, and then
> maybe c(a=1, b=2)[[1]] would give one.
I like to make the distinction between simplifying and preserving
subsetting (maybe not the best names but the best I've been able to
come up with). It's unfortunate (but understandable) that the syntax
is inconsistent between lists and matrices: x[i] / x[[i]], vs x[i, ,
drop = F], x[i, ]
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the R-devel
mailing list