[R] sum the values in a vector as a complete number

Erik Iverson eriki at ccbr.umn.edu
Tue Feb 1 06:55:12 CET 2011


> I am trying to create a function that is able to calculate this sum:
>
> a<-c(2,3,5)
> b<-(8,7)
>
> with "a" meaning 235 and "b" 87. So the result of this sum would be 235 + 87
> = 322.

a <- c(2,3,5)
b <- c(8,7)

vectorToScalar <- function(x) {
   as.numeric(paste(x, collapse = ""))
}

vectorToScalar(a) + vectorToScalar(b)



More information about the R-help mailing list