# NOT RUN {
x1 = iris$Species
x2 = as.integer(iris$Sepal.Length)
# transforms the species vector into integers
to_integer(x1)
# To obtain the "items":
to_integer(x1, add_items = TRUE)
# same but in list form
to_integer(x1, add_items = TRUE, items.list = TRUE)
# transforms x2 into an integer vector from 1 to 4
to_integer(x2, add_items = TRUE)
# To have the sorted items:
to_integer(x2, add_items = TRUE, sorted = TRUE)
# The result can safely be used as an index
res = to_integer(x2, add_items = TRUE, sorted = TRUE, items.list = TRUE)
all(res$items[res$x] == x2)
#
# Multiple vectors
#
# by default, the two vector are fast combined, and items are meaningless
to_integer(x1, x2, add_items = TRUE)
# You can use multi.join to have human-readable values for the items:
to_integer(x1, x2, add_items = TRUE, multi.join = TRUE)
to_integer(x1, x2, add_items = TRUE, multi.join = "; ")
# }
Run the code above in your browser using DataLab