Convert a character vector into 1:xxx
f1 <- class="st" span="span" unlist="unlist">strsplit("cabbage", split=""))->
as.numeric(unclass(factor(f1))) # levels are coded 1:n according to their alphabetical order
as.numeric(unclass(factor(f1, levels=unique(f1)))) # levels are coded 1:n according to their first appearence