| split_fill | R Documentation |
This function splits an object into disjoint sets of values based on a factor, applies a specified function to each set, and returns a new object with the original values replaced by the function's output.
split_fill(x, fac, FUN)
## S4 method for signature 'NeuroVol,factor,function'
split_fill(x, fac, FUN)
x |
The object to split. |
fac |
The |
FUN |
The function used to summarize the sets. |
The FUN function 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, every voxel in the set will be filled with that value in the output vector.
An object of the same class as x, with values replaced by the output of FUN.
## Summarize with mean -- FUN returns a scalar
x <- NeuroSpace(c(10, 10, 10), c(1, 1, 1))
vol <- NeuroVol(rnorm(10 * 10 * 10), x)
fac <- factor(rep(1:10, length.out=1000))
ovol.mean <- split_fill(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 <- split_fill(vol, fac, rev)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.