Skip to content
Prev 169993 / 398506 Next

How to split a character vector into 3 vectors

kayj wrote:
# dummy example data
n = 3
x = replicate(10, paste(sample(letters, n), collapse=""))

y = lapply(1:n, function(i) substr(x, i, i))

# if you need a specific vector
x1 = y[[1]]

# if you really need all three as separate variables
for (i in 1:n)
    assign(paste('x', i, sep=""), y[[i]])

vQ