Generating strings combining letter and number sequences in R
问题 How can i generate this vector in R: x <- c("R11", "R12", "R13", "R21", "R22", "R23", "R31",....) until R7xx for a set of six letters (R, S, D, A, B, X) ? and so on? Without actually typing it. 回答1: Try something like this: m <- expand.grid(c('A','B','D','R','X'),1:7,1:3) apply(m,1,paste0,collapse = "") One way to force a specific, non-alphabetic ordering would be to explicitly indicate it using a factor and then order the results from expand.grid : m <- expand.grid(factor(c('R','A','B','D',