x = c("u", "a", "a", "s", "u", "u")
y = c( 5, 5, 5, 3, 3, 7)
# By default, the index value is based on order of occurrence
to_index(x)
to_index(y)
to_index(x, y)
# Use the order of the input values with sorted=TRUE
to_index(x, sorted = TRUE)
to_index(y, sorted = TRUE)
to_index(x, y, sorted = TRUE)
# To get the values to which the index refer, use items=TRUE
to_index(x, items = TRUE)
# play around with the format of the output
to_index(x, items = TRUE, items.simplify = TRUE) # => default
to_index(x, items = TRUE, items.simplify = FALSE)
# multiple items are always in a data.frame
to_index(x, y, items = TRUE)
# NAs are considered as valid
x_NA = c("u", NA, "a", "a", "s", "u", "u")
to_index(x_NA, items = TRUE)
to_index(x_NA, items = TRUE, sorted = TRUE)
Run the code above in your browser using DataLab