Use formatC and strsplit .
idNums <- c(2, 101, 34, 25, 8) idChars <- formatC(idNums, width = 3, flag = "0") idChars <- strsplit(idChars, "") data.frame( digits1 = sapply(idChars, function(x) x[1]), digits2 = sapply(idChars, function(x) x[2]), digits3 = sapply(idChars, function(x) x[3]) )
A bit cleaner using the stringr package. Replace the call with strsplit with
str_split_fixed(idChars, "", 3)
source share