File: recode.R

package info (click to toggle)
r-cran-intergraph 2.0-4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: sh: 13; makefile: 2
file content (12 lines) | stat: -rw-r--r-- 287 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
# given a vector and a recode matrix replace the values in 'x' that match in
# 'm[,1]' with the corresponding replacements from 'm[,2]'

recode <- function(x, mat)
{
    i <- match(x, mat[,1])
    i2 <- which(!is.na(i))
    i <- i[i2]
    rval <- x
    rval[i2] <- mat[,2][i]
    rval
}