isplitRows: Create an iterator that splits a matrix into block rows

Description Usage Arguments Value See Also Examples

View source: R/isplitRows.R

Description

Create an iterator that splits a matrix into block rows. You can specify either the number of blocks, using the chunks argument, or the maximum size of the blocks, using the chunkSize argument.

Usage

1

Arguments

x

Matrix to iterate over.

...

Passed as the second and subsequent arguments to idiv function. Currently, idiv accepts either a value for chunks or chunkSize.

Value

An iterator that returns submatrices of x.

See Also

idiv, isplitCols

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Split a matrix into submatrices with a maximum of three rows
x <- matrix(1:100, 10)
it <- ihasNext(isplitRows(x, chunkSize=3))
while (hasNext(it)) {
  print(nextElem(it))
}

# Split the same matrix into five submatrices
it <- ihasNext(isplitRows(x, chunks=5))
while (hasNext(it)) {
  print(nextElem(it))
}

Example output

Loading required package: iterators
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1   11   21   31   41   51   61   71   81    91
[2,]    2   12   22   32   42   52   62   72   82    92
[3,]    3   13   23   33   43   53   63   73   83    93
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    4   14   24   34   44   54   64   74   84    94
[2,]    5   15   25   35   45   55   65   75   85    95
[3,]    6   16   26   36   46   56   66   76   86    96
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    7   17   27   37   47   57   67   77   87    97
[2,]    8   18   28   38   48   58   68   78   88    98
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    9   19   29   39   49   59   69   79   89    99
[2,]   10   20   30   40   50   60   70   80   90   100
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1   11   21   31   41   51   61   71   81    91
[2,]    2   12   22   32   42   52   62   72   82    92
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    3   13   23   33   43   53   63   73   83    93
[2,]    4   14   24   34   44   54   64   74   84    94
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    5   15   25   35   45   55   65   75   85    95
[2,]    6   16   26   36   46   56   66   76   86    96
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    7   17   27   37   47   57   67   77   87    97
[2,]    8   18   28   38   48   58   68   78   88    98
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    9   19   29   39   49   59   69   79   89    99
[2,]   10   20   30   40   50   60   70   80   90   100

itertools documentation built on May 31, 2017, 4:48 a.m.