On Sat, Jul 11, 2020 at 8:04 AM Fox, John <j...@mcmaster.ca> wrote: > We've had several solutions, and I was curious about their relative > efficiency. Here's a test
Am I the only person on this mailing list who learnt to program with ASCII...? In theory, the most ***efficient*** solution, is to get the ASCII/UTF8/etc values. Then use a simple (math) formula. No matching, no searching, required ... Here's one possibility: xc <- c ("1", "1a", "1b", "1c", "2", "2a", "2b", "2c") I <- (nchar (xc) == 2) xn <- as.integer (substring (xc, 1, 1) ) xn [I] <- xn [I] + (utf8ToInt (paste (substring (xc [I], 2, 2), collapse="") ) - 96) / 4 xn Unfortunately, this makes R look bad. The corresponding C implementation is simpler and presumably the performance winner. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.