Learn R Programming

neuroim (version 0.0.6)

seriesIter: seriesIter

Description

Construct a series iterator

Usage

seriesIter(x)
"seriesIter"(x)
"seriesIter"(x)

Arguments

x
the object to be iterated over. This is typically an instance of class BrainVector

Value

an iter object from the iterators package.

Methods (by class)

  • SparseBrainVector: get a seriesIter for a SparseBrainVector instance
  • BrainVector: get a series iterator for a BrainVector instance

Examples

Run this code

## create a BrainVector with 10X10X10X10, where the last dimension is 
## by convention the fourth dimension.
bvec <- BrainVector(array(rnorm(10*10*10*10), rep(10,4)), BrainSpace(rep(10,4), c(1,1,1)))
iter <- seriesIter(bvec)

## compute mean of each series
library(foreach)
library(iterators)
foreach(i=iter, .combine=c) %do% { mean(i) }
iter <- seriesIter(bvec)

## combine all series into a matrix
foreach(i=iter, .combine=rbind) %do% { i }

## scale all series, add as columns in matrix.
foreach(i=seriesIter(bvec), .combine=cbind) %do% { scale(i) }

Run the code above in your browser using DataLab