search for: cumsums

Displaying 20 results from an estimated 921 matches for "cumsums".

Did you mean: cumsum
2009 Nov 11
2
partial cumsum
Hello, I am searching for a function to calculate "partial" cumsums. For example it should calculate the cumulative sums until a NA appears, and restart the cumsum calculation after the NA. this: x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10) should become this: 1 3 6 NA 5 11 18 26 35 45 any ideas? thank you and best regards, stefan
2012 Nov 22
4
Using cumsum with 'group by' ?
Hi, First post here. Grateful for any help you can give. I have data which looks like this: id time x 1 12:01 5 1 12:02 14 1 12:03 6 1 12:04 3 2 12:01 98 2 12:02 23 2 12:03 1 2 12:04 4 3 12:01 5 3 12:02 65 3 12:03 23 3 12:04 23 But I want to add a column which is the cumulative sum of X, but only by id. I've used cumsum before, but not
2012 Feb 14
1
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 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 for 1 species over an annual period: "mc_pheno" is the object created from this data:
2011 Nov 26
5
cumsum in 3d arrays
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: http://r.789695.n4.nabble.com/cumsum-in-3d-arrays-tp4110470p4110470.html Sent from the R help mailing
2020 Aug 23
2
sum() vs cumsum() implicit type coercion
Hi I noticed a small inconsistency when using sum() vs cumsum() I have a char-based series > tryjpy$long [1] "0.0022" "-0.0002" "-0.0149" "-0.0023" "-0.0342" "-0.0245" "-0.0022" [8] "0.0003" "-0.0001" "-0.0004" "-0.0036" "-0.001" "-0.0011"
2020 Aug 25
1
sum() vs cumsum() implicit type coercion
>>>>> Tomas Kalibera >>>>> on Tue, 25 Aug 2020 09:29:05 +0200 writes: > On 8/23/20 5:02 PM, Rory Winston wrote: >> Hi >> >> I noticed a small inconsistency when using sum() vs cumsum() >> >> I have a char-based series >> >> > tryjpy$long >> >> [1]
2008 Jun 18
4
inverse cumsum
I've a matrix like this: 1985 1.38 1.27 1.84 2.10 0.59 3.47 1986 1.05 1.13 1.21 1.54 0.21 2.14 1987 1.33 1.21 1.77 1.44 0.27 2.85 1988 1.86 1.06 2.33 2.14 0.55 1.40 1989 2.10 0.65 2.74 2.43 1.19 1.45 1990 1.55 0.00 1.59 1.94 0.99 2.14 1991 0.92
2009 Nov 21
2
how to ignore NA when using cumsum?
...764081 0.1791877 0.2276013 NA I want cumulative sums for each row. Here's the code that works until it reaches an NA, then returns all subsequent values as NA. Adding na.rm=TRUE returns the error: Error in FUN(newX[, i], ...) : 2 arguments passed to 'cumsum' which requires 1 cumsums <- apply(proportion, 1, cumsum) Thank you, Tracy [[alternative HTML version deleted]]
2009 Feb 17
2
cumsum vs. sum
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 reasons for this. Perhaps sum uses clever summing tricks to get more accurate results? In some
2005 May 30
2
trouble with cumsum?
Dear R users, I am using R version 2.0.1 (2004/11/15) on an i386-pc-mingw32 platform. I encounter the following problem while using cumsum: > a <- rep(0.01, 100) > b <- cumsum(a) > sum(a) == 1 [1] TRUE > b[100] == 1 [1] FALSE Am I missing something? Should cumsum have such an outcome? Thanks in advance for any clarifications any of you can offer. Regards, Makram Talih --
2002 Jul 24
4
cumsum and subsets of a data frame?
I have a question about using cumsum on subsets of a data frame. Suppose I have a frame that looks something like this > tmp f x y 1 left 1 0 2 left 2 0 3 left 3 9 4 left 4 10 5 left 5 23 6 left 6 45 7 left 7 13 8 left 8 2 9 left 9 6 10 right 1 10 11 right 2 26 12 right 3 9 13 right 4 50 14 right 5 78 15 right 6 20 16 right 7 7 17 right 8 20 18 right 9 19
2011 May 06
1
Cumsum in Lattice Panel Function
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 values had been stored in the data frame? Here is the code I have so far:
2009 Nov 21
1
how to ignore NA when using cumsum WHILE retaining NAs?
...rwise the cumulative sums add 0 and returns a number where a NA should be. Here's the code that works until it reaches an NA, then returns all subsequent values as NA. Adding na.rm=TRUE returns the error: Error in FUN(newX[, i], ...) : 2 arguments passed to 'cumsum' which requires 1 cumsums <- apply(proportion, 1, cumsum) Thank you for any suggestions, Tracy [[alternative HTML version deleted]]
2010 Oct 12
5
aggregate with cumsum
Hello everybody, Data is myd <- data.frame(id1=rep(c("a","b","c"),each=3),id2=rep(1:3,3),val=rnorm(9)) I want to get a cumulative sum over each of id1. trying aggregate does not work myd$pcum <- aggregate(myd[,c("val")],list(orig=myd$id1),cumsum) Please suggest a solution. In real the dataframe is huge so looping with for and subsetting is not a
2009 Jul 01
1
running count in data.frame
Hi, I need to keep a running count of events that have happened in my data.frame. I found a document called usingR that had an example of doing this for random coin flips and I tried to modify it. It seems to sort of work in the beginning, but then it stops and I don't understand why. I'm trying to duplicate essentially the Excel capability of =SUM($A$1:$A(Row number)) The example
2002 Dec 05
2
Problems with segments and multiple graphs
I would like to create a page of two graphs (2 rows by 1 col) and then draw vertical lines (segments?) on both graphs from the minimum values to the corresponding maximum value. So I have tried # > y <- rnorm(3000) > par(mfrow=c(2,1)) > plot(y,type="l") > plot(cumsum(y),type="l") > segments(1000,min(cumsum(y)),1000,max(cumsum(y))) > par(mfg=c(1,1)) >
2011 Dec 09
3
bug in sum() on integer vector
Hi, x <- c(rep(1800000003L, 10000000), -rep(1200000002L, 15000000)) This is correct: > sum(as.double(x)) [1] 0 This is not: > sum(x) [1] 4996000 Returning NA (with a warning) would also be acceptable for the latter. That would make it consistent with cumsum(x): > cumsum(x)[length(x)] [1] NA Warning message: Integer overflow in 'cumsum'; use
2007 Nov 03
2
cumsum
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,] 1 5 [2,] 2 6 [3,] 3 7 [4,] 4 8 yields: 1 3 6 10 15 21 28 36 I want: [,1] [,2] [1,] 1 5 [2,] 3 11 [3,] 6 18 [4,] 10 26 Is there any command to do so?? best,
2016 Mar 30
2
Compute the Gini coefficient
Hello, I would like to build a Lorenz curve and calculate a Gini coefficient in order to find how much parasites does the top 20% most infected hosts support. Here is my data set: Number of parasites per host: parasites = c(0,1,2,3,4,5,6,7,8,9,10) Number of hosts associated with each number of parasites given above: hosts = c(18,20,28,19,16,10,3,1,0,0,0) To represent the Lorenz curve: I
2017 Jan 20
1
NaN behavior of cumsum
Hi! I noticed that cumsum behaves different than the other cumulative functions wrt. NaN values: > values <- c(1,2,NaN,1) > for ( f in c(cumsum, cumprod, cummin, cummax)) print(f(values)) [1] 1 3 NA NA [1] 1 2 NaN NaN [1] 1 1 NaN NaN [1] 1 2 NaN NaN The reason is that cumsum (in cum.c:33) contains an explicit check for ISNAN. Is that intentional? IMHO, ISNA would be better