fill-methods: Generic function to map values from one set to another using...

Description Usage Arguments Value Examples

Description

Generic function to map values from one set to another using a user-supplied lookup table

Usage

1
2
3
4
5
6
7
fill(x, lookup)

## S4 method for signature 'BrainVolume,list'
fill(x, lookup)

## S4 method for signature 'BrainVolume,matrix'
fill(x, lookup)

Arguments

x

the object to map values from

lookup

the lookup table. The first column is the "key" the second column is the "value".

Value

a new object where the original values have been filled in with the values in the lookup table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
x <- BrainSpace(c(10,10,10), c(1,1,1))
vol <- BrainVolume(sample(1:10, 10*10*10, replace=TRUE), x)

## lookup table is list
lookup <- lapply(1:10, function(i) i*10)
ovol <- fill(vol, lookup)

## lookup table is matrix. First column is key, second column is value
names(lookup) <- 1:length(lookup)
lookup.mat <- cbind(as.numeric(names(lookup)), unlist(lookup))
ovol2 <- fill(vol, lookup.mat)
all.equal(as.vector(ovol2), as.vector(ovol))

neuroim documentation built on May 2, 2019, 1:04 p.m.