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

2011-02-02 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 01.02.2011 07:02:50: > Hi AD, > > You might try the following: > > # data > a <- c(2,3,5) > b <- c(8,7) # you got this wrong ;) > > # option 1 > foo <- function(x) as.numeric(paste(x, sep = "", collapse = "")) > > # examples > foo(a) > # [1] 235 >

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

2011-02-01 Thread Henrique Dallazuanna
Try this: sum(a * c(100, 10, 1)) + sum(b * c(10, 1)) On Tue, Feb 1, 2011 at 2:22 AM, ADias wrote: > > Hi > > 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 > = 32

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

2011-01-31 Thread Jorge Ivan Velez
Hi AD, You might try the following: # data a <- c(2,3,5) b <- c(8,7) # you got this wrong ;) # option 1 foo <- function(x) as.numeric(paste(x, sep = "", collapse = "")) # examples foo(a) # [1] 235 foo(b) # [1] 87 foo(a) + foo(b) # [1] 322 # option 2 foo2 <- function(x, y) foo(x) + foo(y) #

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

2011-01-31 Thread Erik Iverson
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)