Map Words to Colors

Usage

text2color(words, recode.words, colors)

Arguments

words
A vector of words.
recode.words
A vector of unique words or a list of unique word vectors that will be matched against corresponding colors.
colors
A vector of colors of equal in length to recode.words +1 (the +1 is for unmatched words).

Value

Returns a vector of mapped colors equal in length to the words vector.

Description

A dictionary lookup that maps words to colors.

Examples

x <- structure(list(X1 = structure(c(3L, 1L, 8L, 4L, 7L, 2L, 2L, 2L, 4L, 8L, 4L, 3L, 5L, 3L, 1L, 8L, 7L, 2L, 1L, 6L), .Label = c("a", "and", "in", "is", "of", "that", "the", "to"), class = "factor")), .Names = "X1", row.names = c(NA, -20L), class = "data.frame") #blue was recycled text2color(x$X1, c("the", "and", "is"), c("red", "green", "blue"))
Warning message: length of colors should be 1 more than length of recode.words
[1] "blue" "blue" "blue" "blue" "red" "green" "green" "green" "blue" "blue" "blue" "blue" "blue" "blue" "blue" [16] "blue" "red" "green" "blue" "blue"
text2color(x$X1, c("the", "and", "is"), c("red", "green", "blue", "white"))
[1] "white" "white" "white" "blue" "red" "green" "green" "green" "blue" "white" "blue" "white" "white" "white" "white" [16] "white" "red" "green" "white" "white"
x$X2 <- text2color(x$X1, list(c("the", "and", "is"), "that"), c("red", "green", "white")) x
X1 X2 1 in white 2 a white 3 to white 4 is red 5 the red 6 and red 7 and red 8 and red 9 is red 10 to white 11 is red 12 in white 13 of white 14 in white 15 a white 16 to white 17 the red 18 and red 19 a white 20 that green

See also

lookup