[R] NA values in indexing

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Mar 26 17:45:25 CET 2010


On Fri, Mar 26, 2010 at 4:15 PM, Bert Gunter <gunter.berton at gene.com> wrote:
> Is this, from the man page, relevant?
>
> "An empty index selects all values: this is most often used to replace all
> the entries but keep the attributes. "

 No, I think that means doing "x[]", and only in replacement:

> x=101:105
> attr(x,"foo")="Fnord"
> x
[1] 101 102 103 104 105
attr(,"foo")
[1] "Fnord"
> x[]
[1] 101 102 103 104 105
attr(,"foo")
[1] "Fnord"
> x[]=1:5
> x
[1] 1 2 3 4 5
attr(,"foo")
[1] "Fnord"

 as you see, I've replaced all the entries but kept the attributes.

 c(NA,NA,NA) is clearly not empty...

Barry



More information about the R-help mailing list