Re: [R] sequential sum

2012-02-14 Thread C Lin
; CC: r-help@r-project.org > Subject: Re: [R] sequential sum > > > On Feb 14, 2012, at 1:38 PM, Nordlund, Dan (DSHS/RDA) wrote: > > >> -Original Message- > >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > >> project.org] On Behal

Re: [R] sequential sum

2012-02-14 Thread David Winsemius
On Feb 14, 2012, at 1:38 PM, Nordlund, Dan (DSHS/RDA) wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of baccts Sent: Tuesday, February 14, 2012 9:04 AM To: r-help@r-project.org Subject: [R] sequential sum Dear R users, I

Re: [R] sequential sum

2012-02-14 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of baccts > Sent: Tuesday, February 14, 2012 9:04 AM > To: r-help@r-project.org > Subject: [R] sequential sum > > Dear R users, > > I am trying to su

[R] sequential sum

2012-02-14 Thread baccts
Dear R users, I am trying to sum number that exist in another vector up to i, then increment i and repeat. Sorry. It's hard to explain but basically I am trying to do the following: test <- c(1,2,3,4); test2 <- c(3,5,6,7,2,8,8,4,4); test3 <- c(10,20,30,40); tmp <- 0; for (i in 1:length(test)){ tmp

Re: [R] Sequential Sum in R

2011-12-06 Thread Jean V Adams
vioravis wrote on 12/06/2011 12:42:35 PM: > I am trying to code the following excel formula in R. > > ab cResultFormula > 1 10 0.1 #N/A > IF(B2<20,NA(),C2+IF(ISERROR(D1),0,D1)) > 2 20 0.2 0.2 > IF(B3<20,NA

[R] Sequential Sum in R

2011-12-06 Thread vioravis
I am trying to code the following excel formula in R. ab cResultFormula 1 10 0.1 #N/A IF(B2<20,NA(),C2+IF(ISERROR(D1),0,D1)) 2 20 0.2 0.2 IF(B3<20,NA(),C3+IF(ISERROR(D2),0,D2)) 3 30

Re: [R] sequential sum of a vector...

2008-07-23 Thread denise xifaras
  --- On Wed, 7/23/08, Patrizio Frederic <[EMAIL PROTECTED]> wrote: From: Patrizio Frederic <[EMAIL PROTECTED]> Subject: Re: [R] sequential sum of a vector... To: "Shubha Vishwanath Karanth" <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED] Date: Wednesday, July 23, 2008, 8:30 AM

Re: [R] sequential sum of a vector...

2008-07-23 Thread Gustaf Rydevik
On Wed, Jul 23, 2008 at 4:03 PM, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: > Hi R, > > > > Let, > > > > x=1:80 > > > > I want to sum up first 8 elements of x, then again next 8 elements of x, > then again another 8 elements. So, my new vector should look like: > > c(36,100,164,228,29

Re: [R] sequential sum of a vector...

2008-07-23 Thread Henrique Dallazuanna
Maybe: tapply(x, gl(10, 8), sum) or unlist(lapply(split(x, gl(10, 8)), sum)) On Wed, Jul 23, 2008 at 11:03 AM, Shubha Vishwanath Karanth <[EMAIL PROTECTED]> wrote: > Hi R, > > > > Let, > > > > x=1:80 > > > > I want to sum up first 8 elements of x, then again next 8 elements of x, > then again a

Re: [R] sequential sum of a vector...

2008-07-23 Thread William Revelle
At 7:33 PM +0530 7/23/08, Shubha Vishwanath Karanth wrote: Hi R, Let, x=1:80 I want to sum up first 8 elements of x, then again next 8 elements of x, then again another 8 elements. So, my new vector should look like: c(36,100,164,228,292,356,420,484,548,612) I used: aggregate(x,list(rep(1:10

Re: [R] sequential sum of a vector...

2008-07-23 Thread Jorge Ivan Velez
Dear Shubha, Try this: x=1:80 tapply(x,rep(1:10,each=8),sum) 1 2 3 4 5 6 7 8 9 10 36 100 164 228 292 356 420 484 548 612 HTH, Jorge On Wed, Jul 23, 2008 at 10:03 AM, Shubha Vishwanath Karanth < [EMAIL PROTECTED]> wrote: > Hi R, > > > > Let, > > > > x=1:80 > > > > I want to

Re: [R] sequential sum of a vector...

2008-07-23 Thread Richard . Cotton
> x=1:80 > > I want to sum up first 8 elements of x, then again next 8 elements of x, > then again another 8 elements. So, my new vector should look like: > > c(36,100,164,228,292,356,420,484,548,612) > > I used: > > aggregate(x,list(rep(1:10,each=8)),sum)[-1] > > or > > rowsum(x,group=r

Re: [R] sequential sum of a vector...

2008-07-23 Thread Marc Schwartz
on 07/23/2008 09:03 AM Shubha Vishwanath Karanth wrote: Hi R, Let, x=1:80 I want to sum up first 8 elements of x, then again next 8 elements of x, then again another 8 elements. So, my new vector should look like: c(36,100,164,228,292,356,420,484,548,612) I used: a

Re: [R] sequential sum of a vector...

2008-07-23 Thread Shubha Vishwanath Karanth
eying... Thanks, shubha From: Jorge Ivan Velez [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2008 8:59 PM To: Shubha Vishwanath Karanth Cc: [EMAIL PROTECTED] Subject: Re: [R] sequential sum of a vector... Dear Shubha, Try this: x=1:80 tapply(x,rep

Re: [R] sequential sum of a vector...

2008-07-23 Thread Patrizio Frederic
try this colSums(matrix(x,8)) regards, PF +- | Patrizio Frederic | Research associate in Statistics, | Department of Economics, | University of Modena and Reggio Emilia, | Via Berengario 51, | 41100 Modena, Italy | | tel: +39 059 205 6727 | fax:

[R] sequential sum of a vector...

2008-07-23 Thread Shubha Vishwanath Karanth
Hi R, Let, x=1:80 I want to sum up first 8 elements of x, then again next 8 elements of x, then again another 8 elements. So, my new vector should look like: c(36,100,164,228,292,356,420,484,548,612) I used: aggregate(x,list(rep(1:10,each=8)),sum)[-1] or rowsum(x,group=r