How about:
> as.list(data.frame(expand.grid(1:2, 3:5)))
$Var1:
[1] 1 2 1 2 1 2
$Var2:
[1] 3 3 4 4 5 5
hope this helps. spencer graves
Myers, Brent wrote:
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
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
|