Description Usage Arguments See Also Examples
Create an iterator over an array. It is similar to the iapply
function from the iterators package, but it has special support for nested
foreach loops.
1 2 |
X |
Array to iterate over. |
MARGIN |
Vector of subscripts to iterate over. Note that if
the length of |
... |
Used to force subsequent arguments to be specified by name. |
chunks |
Number of elements that the iterator should generate.
This can be a single value or a vector the same length as |
chunkSize |
The maximum size Number of elements that the iterator
should generate.
This can be a single value or a vector the same length as |
drop |
Should dimensions of length 1 be dropped in the generated
values? It defaults to |
idx |
List of length |
quote |
A logical value indicating whether the final iteration values should be quoted or not. This can be useful in a parallel context because it can be much more efficient to send call objects to parallel workers than the objects that they evaluate to. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # Iterate over matrices in a 3D array
x <- array(1:24, c(2,3,4))
as.list(iarray(x, 3))
# Iterate over subarrays
as.list(iarray(x, 3, chunks=2))
x <- array(1:64, c(4,4,4))
it <- iarray(x, c(2,3), chunks=c(1,2))
jt <- nextElem(it)
nextElem(jt)
jt <- nextElem(it)
nextElem(jt)
it <- iarray(x, c(2,3), chunks=c(2,2))
jt <- nextElem(it)
nextElem(jt)
nextElem(jt)
jt <- nextElem(it)
nextElem(jt)
nextElem(jt)
# Use idx to iterate over only the middle four columns of a matrix
x <- matrix(1:18, nrow=3, ncol=6)
it <- iarray(x, 1, idx=list(TRUE, quote(2:5)))
nextElem(it)
nextElem(it)
nextElem(it)
# It can also be done using alist:
it <- iarray(x, 1, idx=alist(, 2:5))
nextElem(it)
nextElem(it)
nextElem(it)
x <- matrix(1:1800, nrow=3, ncol=600)
it <- iarray(x, 1, idx=alist(, 10:600), quote=TRUE)
(yq <- nextElem(it))
object.size(yq)
object.size(eval(yq))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.