Learn R Programming

neuroim (version 0.0.6)

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

Description

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

Usage

fill(x, lookup)
"fill"(x, lookup)
"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

Run this code
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))

Run the code above in your browser using DataLab