I think an example should make things clear enough.
I have
a_1 = 6547
and I want some function that transform a_1 into the following a_2
a_2 = c(6, 5, 4, 7)
I think an example should make things clear enough.
I have
a_1 = 6547
and I want some function that transform a_1 into the following a_2
a_2 = c(6, 5, 4, 7)
This also works. It's slower than the other answers, but possibly easier to read...
This is 3-4x as fast on my computer than doing a strsplit. But the strsplit is a lot more elegant and the difference decreases with longer vectors.
Edit: using Carl's insight, here is a more general version.
Convert to character then split will do the trick
I think you should use power of 10 to do it. And recursivly, downgrade this power , add the part found in vector and remove this to a_1. 6 x 1000, 5 x 100, 4 x 10, 7 x1 .....