Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change a vector into a single number

Tags:

r

vector

Lets say I have a vector x which is

x = c(1,2,3,4,5)

and I want it to have a single length of all the numbers in the vector so that the end result looks like this:

x = 12345

If I then want to example multiply it by 2 it would show: 12345*2 = 24690

Instead of: 1,2,3,4,5 * 2 = 2,4,6,8,10

Any easy way to do it?

like image 364
Yolof Avatar asked Oct 27 '25 07:10

Yolof


1 Answers

Another option with Reduce()

as.numeric(Reduce(paste0, x))
# [1] 12345
like image 127
Darren Tsai Avatar answered Oct 28 '25 20:10

Darren Tsai