[R] indexing problem

Sundar Dorai-Raj sundar.dorai-raj at PDF.COM
Tue Oct 19 19:00:08 CEST 2004



diana.chirac at free.fr wrote:

> Hi,
> 
> I have the following indexing problem, can you help me please ?
> 
> Given:
> dm = a data.frame or a matrix dm,
> idx = a 2 columns (or any number) matrix with the same number of rows as dm
> 
> I want get a subset of dm, for each row, the columns which
> specified by idx.
> 
> thank you, diana
> 

Diana,
   From what I gather it appears as if you want to split dm by all the 
unique rows of idx? Is that right? If so, you can do the following:

x <- split(dm, do.call("paste", as.data.frame(idx))

This will split dm into a list with each element a subset of dm 
corresponding to a unique row in idx. The length of the x will be the 
number of unique rows in idx.

If this is not what you want, please provide an example and what you 
expect to see.

--sundar




More information about the R-help mailing list