[R] confusion with R syntax

Leeds, Mark (IED) Mark.Leeds at morganstanley.com
Thu Oct 11 21:34:22 CEST 2007


I just noticed something by accident with R syntax that I'm sure is
correct but I don't understand it. If I have
a simple numeric vector x and I subscript it, it seems that I can then
subscript a second time with TRUE
or FALSE, sort of like a 2 dimensional array in C. Does someone know if
this is documented somewhere
Because it's neat but I never knew it existed. To me it seems like a 1
dimensional vector should
have only one dimensional indexing ?

x <- seq(1,10)
> x
 [1]  1  2  3  4  5  6  7  8  9 10
> x[2:4][c(TRUE,FALSE,TRUE)]
[1] 2 4

But, it only works for TRUE or FALSE and not numbers so I think it's not
really 2 dimensional indexing.

x[1][2]

[1] NA

If someone could explain this mechanism or tell me what I should look
for in the archives, it would
be appreciated. Thanks.
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to bu...{{dropped:22}}



More information about the R-help mailing list