Learn R Programming

neuroim (version 0.0.6)

splitFill: Generic function to fill disjoint sets of values with the output of a function

Description

Generic function to fill disjoint sets of values with the output of a function

Usage

splitFill(x, fac, FUN)
"splitFill"(x, fac, FUN)

Arguments

x
the object to split
fac
the factor to split by
FUN
the function to summarize the the sets

Value

a new object where the original values have been replaced by the function output

Details

FUN can either return a scalar for each input vector or a vector equal to the length of the input vector. If it returns a scalar then every voxel in the set will be filled with that value in the output vector.

Examples

Run this code

## summarize with mean -- FUN returns a scalar
x = BrainSpace(c(10,10,10), c(1,1,1))
vol <- BrainVolume(rnorm(10*10*10), x)
fac <- factor(rep(1:10, length.out=1000))
ovol.mean <- splitFill(vol, fac, mean)
identical(dim(ovol.mean), dim(vol))
length(unique(as.vector(ovol.mean))) == 10
## transform by reversing vector -- FUN returns a vector.
ovol2 <- splitFill(vol, fac, rev)

Run the code above in your browser using DataLab