Learn R Programming

neuroim2 (version 0.8.5)

map_values: Map Values from One Set to Another Using a User-supplied Lookup Table

Description

This function maps values from one set to another using a lookup table provided by the user.

Usage

map_values(x, lookup)

# S4 method for NeuroVol,list map_values(x, lookup)

# S4 method for NeuroVol,matrix map_values(x, lookup)

Value

An object of the same class as x, in which the original values have been replaced with the lookup table values.

Arguments

x

The object from which values will be mapped.

lookup

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

Examples

Run this code
x <- NeuroSpace(c(10, 10, 10), c(1, 1, 1))
vol <- NeuroVol(sample(1:10, 10 * 10 * 10, replace = TRUE), x)

## Lookup table is a list
lookup <- lapply(1:10, function(i) i * 10)
names(lookup) <- 1:10
ovol <- map_values(vol, lookup)

## Lookup table is a matrix. The first column is the key, and the second column is the value
names(lookup) <- 1:length(lookup)
lookup.mat <- cbind(as.numeric(names(lookup)), unlist(lookup))
ovol2 <- map_values(vol, lookup.mat)
all.equal(as.vector(ovol2), as.vector(ovol))

Run the code above in your browser using DataLab