s-news
[Top] [All Lists]

FW: List of vectors from expand.grid

To: <s-news@lists.biostat.wustl.edu>
Subject: FW: List of vectors from expand.grid
From: "Myers, Brent" <MyersDB@missouri.edu>
Date: Fri, 30 May 2003 07:52:35 -0500
Thread-index: AcMmLu5PdUpnpQSkRuS1ARQf/tyToQAezmSQ
Thread-topic: List of vectors from expand.grid
> S community,
> 
> I am using expand.grid to flexibly create a set of cell indexes(i,,j) from 
> the dimensions of any matrix passed to a function.
> 
> How can I get the expand.grid output into the form of a list of vectors?
> 
> e.g list of cell index vectors
> [[1]]:
> [1] 1 1
> 
> [[2]]:
> [1] 1 2
> 
> [[3]]:
> [1] i j
> 
> Here is my case
> 
> #Get dimensions of any matrix or array
> idx.limits <-dim(acube)
> 
> #Generate the list of (planar) central cell index combinations
> ccidx <- expand.grid (1:idx.limits[1], 1:idx.limits[2])
> 
> I can try...
> ccidx.matrix <- matrix(c(ccidx[[1]], ccidx[[2]]), length(ccidx[[1]]))
> 
> to get a matrix, and then ...
> ccidx.list <- apply(ccidx.matrix, 1, c)
> 
> to collapse along the rows, But c doesn't work as expected. Sum adds along 
> rows, but concatenate doesn't work that way?
> 
> D. Brent Myers
> Research Specialist - Agronomy
> University of Missouri
> 158 Ag Engineering Building
> Columbia, MO 65211
> 
> 
> 

<Prev in Thread] Current Thread [Next in Thread>