split_fill-methods: Fill Disjoint Sets of Values with the Output of a Function

split_fillR Documentation

Fill Disjoint Sets of Values with the Output of a Function

Description

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.

Usage

split_fill(x, fac, FUN)

## S4 method for signature 'NeuroVol,factor,function'
split_fill(x, fac, FUN)

Arguments

x

The object to split.

fac

The factor to split by.

FUN

The function used to summarize the sets.

Details

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.

Value

A new object in which the original values have been replaced by the output of the function.

Examples

## 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)


bbuchsbaum/neuroim2 documentation built on April 20, 2024, 4:20 p.m.