This function aims to assign an id to factor or similar character strings. Regarding factors, as.integer() does such task but the order obtained may differ.

assignIds(x, alphabetical = FALSE)

Arguments

x

an R object to be coerced into character type.

alphabetical

a logical indicating whether an alphabetical sorting must be applied.

Value

A vector of Ids.

Examples

assignIds(list(2,'f', 'd', 'f'))
#> [1] 1 2 3 2