I'm have difficulty figuring out how to select specific rows from
arrays inside a list. The catch is that I want to select *different*
rows from different segments of the array. Here's an example. I've
got a list called stuff that contains two 3-dimensional arrays (the
reason stuff is a list instead of an array is due to earlier steps in
the program, where the sizes of the arrays are not the same).
stuff <- list(array(1:24, dim=c(3, 4, 2)),
array(25:48, dim=c(3, 4, 2)))
[[1]]:
, , 1
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
, , 2
[,1] [,2] [,3] [,4]
[1,] 13 16 19 22
[2,] 14 17 20 23
[3,] 15 18 21 24
[[2]]:
, , 1
[,1] [,2] [,3] [,4]
[1,] 25 28 31 34
[2,] 26 29 32 35
[3,] 27 30 33 36
, , 2
[,1] [,2] [,3] [,4]
[1,] 37 40 43 46
[2,] 38 41 44 47
[3,] 39 42 45 48
And I've got another 3-dimensional array, pickrow, which I would like
to use to select rows from the list above. The data in the array are
the row numbers I would like to select, and so relate to dimension 1
in the arrays in stuff. (Dimension 1 in pickrow relates to dimension
3 in stuff, and dimension 3 in pickrow relates to the list elements in
stuff. Have I lost you yet?)
pickrow <- array(sample(1:3, 12, T), dim=c(2, 3, 2))
, , 1
[,1] [,2] [,3]
[1,] 3 1 3
[2,] 1 1 2
, , 2
[,1] [,2] [,3]
[1,] 1 1 2
[2,] 3 3 3
If I knew the magic words, I would be able to create a new list,
newstuff, that looked like this (dimnames unimportant):
[[1]]:
, , 1
[,1] [,2] [,3] [,4]
[3,] 3 6 9 12
[1,] 1 4 7 10
[3,] 3 6 9 12
, , 2
[,1] [,2] [,3] [,4]
[1,] 13 16 19 22
[1,] 13 16 19 22
[2,] 14 17 20 23
[[2]]:
, , 1
[,1] [,2] [,3] [,4]
[1,] 25 28 31 34
[1,] 25 28 31 34
[2,] 26 29 32 35
, , 2
[,1] [,2] [,3] [,4]
[3,] 39 42 45 48
[3,] 39 42 45 48
[3,] 39 42 45 48
I would appreciate any suggestions you might be able to offer. Send
them to me and I will summarize to the list. Thanks.
JVA
Jean V. Adams USGS Biological Resources Division
e-mail: jean_adams@usgs.gov Great Lakes Science Center
phone: (734) 214-9307 1451 Green Road
FAX: 734-994-8780 Ann Arbor, MI 48105-2899 USA
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|