[R] Problem with indexing (subscript out of bounds)

From: Nils Trebing <nils.trebing_at_gmx.de>
Date: Sun 11 Dec 2005 - 11:00:51 EST


Hi,

I am trying to index the rows of a model matrix where, due to missing values in the dataset used for the regression, the row numbers sometimes "jump" like this:

> X[17:19,]

   (Intercept) PCINIFM

17           1 36.76471
19           1 13.23529
20           1 32.35294

So, the problem is if I select for example X[20, ], I actually get the 21th observation. I've tried to work around this problem by using X[as.character(20) , ]. Thus I actually get what I want. However, I need to access sequences of rows, but if there is some missing row, this doesn't work:

> X[as.character(17:19),]

Error: subscript out of bounds

Is there a way to make R handle this more gracefully, so that, in this case, it would just return the rows 17 and 19 without complaining?

I apologize in advance for this dumb question of the beginner who I am and for which I didn't find a solution in the documentation!

Thanks in advance,
Nils



R-help@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 Received on Sun Dec 11 11:09:51 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:35 EST