/usr/lib/R/site-library/gdata/doc/mapLevels.R is in r-cran-gdata 2.18.0-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | ### R code from vignette source 'mapLevels.Rnw'
###################################################
### code chunk number 1: ex01
###################################################
library(gdata)
(fac <- factor(c("B", "A", "Z", "D")))
(map <- mapLevels(x=fac))
###################################################
### code chunk number 2: ex02
###################################################
(int <- as.integer(fac))
mapLevels(x=int) <- map
int
identical(fac, int)
###################################################
### code chunk number 3: ex03
###################################################
str(map)
###################################################
### code chunk number 4: ex04
###################################################
map[[2]] <- as.integer(c(1, 2))
map
int <- as.integer(fac)
mapLevels(x=int) <- map
int
###################################################
### code chunk number 5: ex05
###################################################
(f1 <- factor(c("A", "D", "C")))
(f2 <- factor(c("B", "D", "C")))
###################################################
### code chunk number 6: ex06
###################################################
fTest <- f1
levels(fTest) <- c("A", "B", "C", "D")
fTest
###################################################
### code chunk number 7: ex07
###################################################
fTest <- f1
levels(fTest) <- list(A="A", B="B",
C="C", D="D")
fTest
###################################################
### code chunk number 8: ex08
###################################################
(bigMap <- mapLevels(x=list(f1, f2),
codes=FALSE,
combine=TRUE))
mapLevels(f1) <- bigMap
mapLevels(f2) <- bigMap
f1
f2
cbind(as.character(f1), as.integer(f1),
as.character(f2), as.integer(f2))
|