# How to split a number into digits in R?

To split a number into digits in R, we can use strsplit function by reading the number with as.character and then reading the output with as.numeric.

For example, if we have a number stored into an object called X then we can split the number stored in X into digits by using the command as follows −

as.numeric(strsplit(as.character(X),"")[])

## Example 1

To split a number into digits in R, use the snippet given below −

x1<-2547435
x1

If you execute the above given snippet, it generates the following output −

 2547435

To split a number into digits in R, add the following code to the above snippet −

x1<-2547435
as.numeric(strsplit(as.character(x1),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 2 5 4 7 4 3 5

## Example 2

To split a number into digits in R, use the snippet given below −

x2<-8789342355
x2

If you execute the above given snippet, it generates the following output −

 8789342355

To split a number into digits in R, add the following code to the above snippet −

x2<-8789342355
as.numeric(strsplit(as.character(x2),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 8 7 8 9 3 4 2 3 5 5

## Example 3

To split a number into digits in R, use the snippet given below −

x3<-10000
x3

If you execute the above given snippet, it generates the following output −

 10000

To split a number into digits in R, add the following code to the above snippet −

x3<-10000
as.numeric(strsplit(as.character(x3),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 1 0 0 0 0

## Example 4

To split a number into digits in R, use the snippet given below −

x4<-rpois(1,200)
x4

If you execute the above given snippet, it generates the following output −

 207

To split a number into digits in R, add the following code to the above snippet −

x4<-rpois(1,200)
as.numeric(strsplit(as.character(x4),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 2 0 7

## Example 5

To split a number into digits in R, use the snippet given below −

x5<-47824135
x5

If you execute the above given snippet, it generates the following output −

 47824135

To split a number into digits in R, add the following code to the above snippet −

x5<-47824135
as.numeric(strsplit(as.character(x5),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 4 7 8 2 4 1 3 5

## Example 6

To split a number into digits in R, use the snippet given below −

x6<-231404700
x6

If you execute the above given snippet, it generates the following output −

 231404700

To split a number into digits in R, add the following code to the above snippet −

x6<-231404700
as.numeric(strsplit(as.character(x6),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 2 3 1 4 0 4 7 0 0

## Example 7

To split a number into digits in R, use the snippet given below −

x7<-00142452233
x7

If you execute the above given snippet, it generates the following output −

 142452233

To split a number into digits in R, add the following code to the above snippet −

x7<-00142452233
as.numeric(strsplit(as.character(x7),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 1 4 2 4 5 2 2 3 3

## Example 8

To split a number into digits in R, use the snippet given below −

x8<-rpois(1,100032474)
x8

If you execute the above given snippet, it generates the following output −

 100035562

To split a number into digits in R, add the following code to the above snippet −

x8<-rpois(1,100032474)
as.numeric(strsplit(as.character(x8),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 1 0 0 0 3 5 5 6 2

## Example 9

To split a number into digits in R, use the snippet given below −

x9<-rpois(1,2875662365)
x9

If you execute the above given snippet, it generates the following output −

 NA

To split a number into digits in R, add the following code to the above snippet −

as.numeric(strsplit(as.character(x9),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 2 8 7 5 6 7 2 5 3 2

## Example 10

To split a number into digits in R, use the snippet given below −

x10<-rpois(1,924135746)
x10

If you execute the above given snippet, it generates the following output −

 924151778

To split a number into digits in R, add the following code to the above snippet −

x10<-rpois(1,924135746)
as.numeric(strsplit(as.character(x10),"")[])

## Output

If you execute all the above given codes as a single program, it generates the following output −

 9 2 4 1 5 1 7 7 8