map_values | R Documentation |
This function maps values from one set to another using a lookup table provided by the user.
map_values(x, lookup)
## S4 method for signature 'NeuroVol,list'
map_values(x, lookup)
## S4 method for signature 'NeuroVol,matrix'
map_values(x, lookup)
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". |
An object of the same class as x
, in which the original values have been replaced with the lookup table values.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.