How to extract a number into digits using R?

digits, extract, numbers, r

Solution

Alternatively, with `strsplit`:

x <- as.character(4321)
as.numeric(unlist(strsplit(x, "")))
[1] 4 3 2 1

Problem

Suppose I have a number: 4321 and I want to extract it into digits: 4, 3, 2, 1 How do I do this?

Original source