Heinz,> x <- c("a","b","c") > lettersnum <- 1:length(letters[]) > names(lettersnum) <- letters[] > lettersnum[x] > > lettersnum[x] > a b c > 1 2 3i'm not sure if the following is obviously better, but one might do ----> b <- match(a, a) > names(b) <- a > ba b c 1 2 3 ---- cheers, Greg
Greg, Greg Minshall wrote/hat geschrieben on/am 02.11.2021 08:57:> Heinz, > >> x <- c("a","b","c") >> lettersnum <- 1:length(letters[]) >> names(lettersnum) <- letters[] >> lettersnum[x] >>> lettersnum[x] >> a b c >> 1 2 3 > > i'm not sure if the following is obviously better, but one might do > ---- >> b <- match(a, a) >> names(b) <- a >> b > a b c > 1 2 3 > ---- > > cheers, Greg >You are right - match seems obviously better, but why not do x <- c("a","b","c") match(x, letters[]) best, Heinz