Re: [R] cumsum function to determine plankton phenology

2012-02-14 Thread David L Carlson
..@r-project.org] On Behalf Of Heather Anne Wright Sent: Tuesday, February 14, 2012 10:35 AM To: r-help@r-project.org Subject: [R] cumsum function to determine plankton phenology Apologies for the empty email earlier! I have species abundance data sampled at a weekly frequency or sometimes monthly depen

[R] cumsum function to determine plankton phenology

2012-02-14 Thread Heather Anne Wright
Apologies for the empty email earlier! I have species abundance data sampled at a weekly frequency or sometimes monthly depending on the year. The goal is to identify the dates in an annual cycle in which the cumulative abundance of a species reaches some threshold. Here's an example of the data

[R] cumsum formula to determine plankton phenology

2012-02-14 Thread Heather Anne Wright
Dear R-users -- -- Heather Anne --- Heather A. Wright, PhD candidate Ecology and Evolution of Plankton Stazione Zoologica Anton Dohrn Villa Comunale 80121 - Napoli, Italy website

Re: [R] cumsum in 3d arrays

2011-11-29 Thread zloncaric
Yes exactly what I want! Thank you very much for your help. -- View this message in context: http://r.789695.n4.nabble.com/cumsum-in-3d-arrays-tp4110470p4118432.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mail

Re: [R] cumsum in 3d arrays

2011-11-28 Thread William Dunlap
ge- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of zloncaric > Sent: Saturday, November 26, 2011 6:32 AM > To: r-help@r-project.org > Subject: [R] cumsum in 3d arrays > > Hello! > > Is it posible to apply /cumsum()/ along the

Re: [R] cumsum in 3d arrays

2011-11-28 Thread Dennis Murphy
Hi: Could you supply a small reproducible example with the output that you expect? For example, what output would you expect from the following: a <- array(1:24, c(2, 2, 3)) ? Dennis On Mon, Nov 28, 2011 at 12:32 AM, zloncaric wrote: > Thank you for your time and help. > > I'm quite aware that

Re: [R] cumsum in 3d arrays

2011-11-28 Thread zloncaric
Thank you for your time and help. I'm quite aware that this problem seems as basic stuff, and of course I've read several R and matlab manuals, and also consulted the D. Hiebeler, Matlab / R Reference and several others, but none of the suggested solutions seems to give me the right result. I've

Re: [R] cumsum in 3d arrays

2011-11-26 Thread David Winsemius
On Nov 26, 2011, at 11:24 AM, David Winsemius wrote: On Nov 26, 2011, at 9:32 AM, zloncaric wrote: Hello! Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array? Something like matrlab function - /cumsum (*A*,dim)/ which returns the cumulative sum of the elements along th

Re: [R] cumsum in 3d arrays

2011-11-26 Thread David Winsemius
On Nov 26, 2011, at 9:32 AM, zloncaric wrote: Hello! Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array? Something like matrlab function - /cumsum (*A*,dim)/ which returns the cumulative sum of the elements along the dimension of *A* specified by scalar dim. `apply` lets

Re: [R] cumsum in 3d arrays

2011-11-26 Thread Ben Bolker
zloncaric biologija.unios.hr> writes: > Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array? > Something like matrlab function - /cumsum (*A*,dim)/ which returns the > cumulative sum of the elements along the dimension of *A* specified by > scalar dim. Check out the combinat

[R] cumsum in 3d arrays

2011-11-26 Thread zloncaric
Hello! Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array? Something like matrlab function - /cumsum (*A*,dim)/ which returns the cumulative sum of the elements along the dimension of *A* specified by scalar dim. Thanks in advance Željka -- View this message in context:

Re: [R] Cumsum in Lattice Panel Function

2011-05-11 Thread Elliot Joel Bernstein
That worked perfectly. Thanks! - Elliot On Mon, May 09, 2011 at 12:20:36AM +0530, Deepayan Sarkar wrote: > On Fri, May 6, 2011 at 9:24 PM, Elliot Joel Bernstein > wrote: > > I'm trying to create an xyplot with a "groups" argument where the y-variable > > is the cumsum of the values stored in the

Re: [R] Cumsum in Lattice Panel Function

2011-05-08 Thread Deepayan Sarkar
On Fri, May 6, 2011 at 9:24 PM, Elliot Joel Bernstein wrote: > I'm trying to create an xyplot with a "groups" argument where the y-variable > is the cumsum of the values stored in the input data frame. I almost have > it, but I can't get it to automatically adjust the y-axis scale. How do I > get

[R] Cumsum in Lattice Panel Function

2011-05-06 Thread Elliot Joel Bernstein
I'm trying to create an xyplot with a "groups" argument where the y-variable is the cumsum of the values stored in the input data frame. I almost have it, but I can't get it to automatically adjust the y-axis scale. How do I get the y-axis to automatically scale as it would have if the cumsum value

Re: [R] cumsum while maintaining NA

2011-04-02 Thread Pete Brecknock
Here's one way . Lines<-"x1 x2 x3 x4 x5 x6 NA NA 3 4 NA NA 5 3 4 NA NA NA 7 3 4 4 NA NA 11 3 4 5 NA NA 67 4 4 NA NA NA" d <- read.table(textConnection(Lines), header = TRUE, colClasses=c("integer")) closeAllConnections() res = t(apply(d, 1, function(x) ave(x,is.na(x),FUN=cumsum))) print(res

Re: [R] Cumsum with a max and min value

2010-11-25 Thread jim holtman
Does this do it; > pmin(2, pmax(-2, cumsum(a))) [1] 0 1 1 2 2 2 1 0 0 -1 -2 On Thu, Nov 25, 2010 at 3:44 PM, henrique wrote: > I have a vector of values -1, 0, 1, say > > > > a <- c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1) > > > > I want to create a vector of the cumulative sum of this,

Re: [R] Cumsum with a max and min value

2010-11-25 Thread Gabor Grothendieck
On Thu, Nov 25, 2010 at 3:44 PM, henrique wrote: > I have a vector of values -1, 0, 1, say > > a <- c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1) > > I want to create a vector of the cumulative sum of this, but I need to set a > maximum and minimum value for the cumsum, for example: > > max_value <- 2 >

Re: [R] Cumsum with a max and min value

2010-11-25 Thread Henrique Dallazuanna
Try this: ac <- cumsum(a) ifelse(ac > 2, max_value, ifelse(ac < -2, min_value, ac)) On Thu, Nov 25, 2010 at 6:44 PM, henrique wrote: > I have a vector of values -1, 0, 1, say > > > > a <- c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1) > > > > I want to create a vector of the cumulative sum of this, bu

[R] Cumsum with a max and min value

2010-11-25 Thread henrique
I have a vector of values -1, 0, 1, say a <- c(0, 1, 0, 1, 1, -1, -1, -1, 0, -1, -1) I want to create a vector of the cumulative sum of this, but I need to set a maximum and minimum value for the cumsum, for example: max_value <- 2 min_value <- -2 the expected result would be (0, 1

Re: [R] cumsum function with data frame

2010-06-03 Thread Jorge Ivan Velez
;> > >> > >> - Original Message > >> > From: Felipe Carrillo > >> > To: Joris Meys ; "n.via...@libero.it" > >> > > >> > Cc: r-help@r-project.org > >> > Sent: Thu, June 3, 2010 11:28:58 AM > >> > Sub

Re: [R] cumsum function with data frame

2010-06-03 Thread Joris Meys
>> AAO1    2005  2 >> AAO1  2006  4"),header=T) >> >> ddply(Data,.(variable),transform,CUMSUM=cumsum(value)) >> >> >> >> >> - Original Message >> > From: Felipe Carrillo >> > To: Joris Mey

Re: [R] cumsum function with data frame

2010-06-03 Thread Jorge Ivan Velez
--- > > From: Felipe Carrillo > > To: Joris Meys ; "n.via...@libero.it" < > n.via...@libero.it> > > Cc: r-help@r-project.org > > Sent: Thu, June 3, 2010 11:28:58 AM > > Subject: Re: [R] cumsum function with data frame > > > > You can also use

Re: [R] cumsum function with data frame

2010-06-03 Thread Felipe Carrillo
le),transform,CUMSUM=cumsum(value))   - Original Message > From: Felipe Carrillo > To: Joris Meys ; "n.via...@libero.it" > > Cc: r-help@r-project.org > Sent: Thu, June 3, 2010 11:28:58 AM > Subject: Re: [R] cumsum function with data frame > > You can

Re: [R] cumsum function with data frame

2010-06-03 Thread Felipe Carrillo
roject.org > Sent: Thu, June 3, 2010 9:26:17 AM > Subject: Re: [R] cumsum function with data frame > > See ?split and ?unsplit. Data <- > read.table(textConnection("variable        Year    >   value EC01            2005    >     5 EC01            2006  >       10

Re: [R] cumsum function with data frame

2010-06-03 Thread Joris Meys
See ?split and ?unsplit. Data <- read.table(textConnection("variableYear value EC01 2005 5 EC01 2006 10 AAO12005 2 AAO1 2006 4"),header=T) Datalist <-split(Data,Data$variable) resultlist <- lapply(Datali

[R] cumsum function with data frame

2010-06-03 Thread n.via...@libero.it
Dear list, I have a problem with the cumsum function. I have a data frame like the following one variableYear value EC01 2005 5 EC01 2006 10 AAO12005 2 AAO1 2006 4 what I would like to obtain is varia

Re: [R] cumsum output

2010-05-10 Thread Felipe Carrillo
th.ethz.ch >Sent: Mon, May 10, 2010 2:33:03 PM >Subject: Re: [R] cumsum output > >It is working correctly,  You have NAs in your data, so you get NAs in the >cumsum. > > >On Mon, May 10, 2010 at 5:09 PM, Felipe Carrillo >wrote: > >Hi: Thanks to Dennis and Fernando

Re: [R] cumsum output

2010-05-10 Thread jim holtman
It is working correctly, You have NAs in your data, so you get NAs in the cumsum. On Mon, May 10, 2010 at 5:09 PM, Felipe Carrillo wrote: > Hi: Thanks to Dennis and Fernando for your help reordering the levels. > Now I have a different issue: > I am trying to get the cumulative weekly values usi

[R] cumsum output

2010-05-10 Thread Felipe Carrillo
Hi: Thanks to Dennis and Fernando for your help reordering the levels. Now I have a different issue: I am trying to get the cumulative weekly values using cumsum and it appears to output the wrong values. Here's my dataset: winter <-  structure(list(week = c(26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L

Re: [R] cumsum for matrix

2010-03-18 Thread Jorge Ivan Velez
Hi ManInMoon, Perhaps the following apply(yourmatrix, 2, cumsum, na.rm = TRUE) ? See ?cumsum and ?apply for more information. HTH, Jorge On Thu, Mar 18, 2010 at 10:01 AM, ManInMoon <> wrote: > > IIs there an equivalent of cumsum for a matrix? i.e cumsum is applied to > each > column ? > > >

[R] cumsum for matrix

2010-03-18 Thread ManInMoon
IIs there an equivalent of cumsum for a matrix? i.e cumsum is applied to each column ? -- View this message in context: http://n4.nabble.com/cumsum-for-matrix-tp1597985p1597985.html Sent from the R help mailing list archive at Nabble.com. __ R-help@

Re: [R] cumsum vs. sum

2009-02-18 Thread Stavros Macrakis
Duncan, Berwin, Martin, Thanks for your thoughtful explanations, which make perfect sense. May I simply suggest that the non-identity between last(cumsum) and sum might be worth mentioning in the cumsum doc page? -s __ R-help@r-project.org

Re: [R] cumsum vs. sum

2009-02-18 Thread Berwin A Turlach
G'day all, On Wed, 18 Feb 2009 12:41:27 -0500 Stavros Macrakis wrote: > Hmm. Why not use the same method to guarantee the same result? Hmm, I did not look at the source code but, potentially, sum() could use some tricks to reduce rounding errors further that would not be available to cumsum(

Re: [R] cumsum vs. sum

2009-02-18 Thread Duncan Murdoch
On 18/02/2009 12:41 PM, Stavros Macrakis wrote: Hmm. Why not use the same method to guarantee the same result? Or at least document the possibility that cumsum(x)[length(x)] != sum(x)... that seems like an easy trap to fall into. Assuming equality of floating point numbers computed by two dif

Re: [R] cumsum vs. sum

2009-02-18 Thread Stavros Macrakis
Hmm. Why not use the same method to guarantee the same result? Or at least document the possibility that cumsum(x)[length(x)] != sum(x)... that seems like an easy trap to fall into. -s On Wed, Feb 18, 2009 at 11:39 AM, Martin Maechler wrote: >> "SM" == Stavros Macrakis >>

Re: [R] cumsum vs. sum

2009-02-18 Thread Martin Maechler
> "SM" == Stavros Macrakis > on Wed, 18 Feb 2009 10:00:40 -0500 writes: SM> Nice! Glad to hear it. It sounds as though it is still possible for SM> cumsum(x)[length(x)] to not be exactly equal to sum, though? Well, possible, probably yes, platform-dependently; However I vag

Re: [R] cumsum vs. sum

2009-02-18 Thread Martin Maechler
> "GaGr" == Gabor Grothendieck > on Tue, 17 Feb 2009 20:53:18 -0500 writes: GaGr> Check out sum.exact and cumsum.exact in the caTools package. >> library(caTools) GaGr> Loading required package: bitops >> x <- 1/(12:14) >> sum(x) - cumsum(x)[3] GaGr> [1] 2.7755

Re: [R] cumsum vs. sum

2009-02-17 Thread Gabor Grothendieck
Check out sum.exact and cumsum.exact in the caTools package. > library(caTools) Loading required package: bitops > x <- 1/(12:14) > sum(x) - cumsum(x)[3] [1] 2.775558e-17 > sum.exact(x) - cumsum.exact(x)[3] [1] 0 On Tue, Feb 17, 2009 at 5:12 PM, Stavros Macrakis wrote: > I recently traced a bug

[R] cumsum vs. sum

2009-02-17 Thread Stavros Macrakis
I recently traced a bug of mine to the fact that cumsum(s)[length(s)] is not always exactly equal to sum(s). For example, x<-1/(12:14) sum(x) - cumsum(x)[3] => 2.8e-17 Floating-point addition is of course not exact, and in particular is not associative, so there are various possible r

Re: [R] cumsum list..

2008-03-14 Thread yoooooo
Yes! mapply is awesome! Thanks. Gabor Csardi wrote: > > cumsum( mapply(function(i,j) sum(a$data[i:j]), x, y) ) > > Is this what you want? > Gabor > > On Thu, Mar 13, 2008 at 06:02:13AM -0700, yoo wrote: >> >> Hi all, i have the following.. >> >> a <- data.frame(data = seq(1,10)) >> >

Re: [R] cumsum list..

2008-03-13 Thread Julian Burgos
In this case you can simply do cumsum(a[x,]+a[y,]) Julian yoo wrote: > Hi all, i have the following.. > > a <- data.frame(data = seq(1,10)) > > i have indices: > x <- c(1, 5, 3, 9) > y <- c(2, 7, 4, 10) > > I want the cumsum of a[1:2], a[5:7], a[3:4]... > > is there an elegant way to

Re: [R] cumsum list..

2008-03-13 Thread Gabor Csardi
cumsum( mapply(function(i,j) sum(a$data[i:j]), x, y) ) Is this what you want? Gabor On Thu, Mar 13, 2008 at 06:02:13AM -0700, yoo wrote: > > Hi all, i have the following.. > > a <- data.frame(data = seq(1,10)) > > i have indices: > x <- c(1, 5, 3, 9) > y <- c(2, 7, 4, 10) > > I want the

[R] cumsum list..

2008-03-13 Thread yoooooo
Hi all, i have the following.. a <- data.frame(data = seq(1,10)) i have indices: x <- c(1, 5, 3, 9) y <- c(2, 7, 4, 10) I want the cumsum of a[1:2], a[5:7], a[3:4]... is there an elegant way to do it without any loop? Thanks! -- View this message in context: http://www.nabble.com/cumsum-l

Re: [R] cumsum

2007-11-05 Thread ONKELINX, Thierry
of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens threshold Verzonden: zaterdag 3 november 2007 12:42 Aan: r-help@r-project.org Onderwerp: [R] cumsum Hi, my problem belongs to the basic ones. I want to

Re: [R] cumsum

2007-11-03 Thread Sundar Dorai-Raj
threshold said the following on 11/3/2007 4:41 AM: > Hi, my problem belongs to the basic ones. I want to get cumulated sum over > the matrix columns by one command (if such exists). Ordinary R's cumsum(x) > when x is: > [,1] [,2] > [1,]15 > [2,]26 > [3,]37 > [4,]4

[R] cumsum

2007-11-03 Thread threshold
Hi, my problem belongs to the basic ones. I want to get cumulated sum over the matrix columns by one command (if such exists). Ordinary R's cumsum(x) when x is: [,1] [,2] [1,]15 [2,]26 [3,]37 [4,]48 yields: 1 3 6 10 15 21 28 36 I want: [,1] [,2] [1,]