Questions tagged [cumsum]

Cumsum is a MatLab, NumPy, Pandas and R function that returns the cumulative sum along different dimensions of an array.

Cumsum is a MatLab, NumPy, Pandas and R function that returns the cumulative sum along different dimensions of an array.

799 questions
-1
votes
3 answers

R how to take top values by group until its sum exceeds a value

i have a data frame like this set.seed(500) df=data.frame(group=c(rep("A",20),rep("B",20),rep("C",20),rep("D",20)),value=round(runif(80,min=1,max=100))) for each group i want to take the top value rows until their sum exceed/meet the target…
santoku
  • 3,297
  • 7
  • 48
  • 76
-1
votes
3 answers

Use function like cumulative sum by group or by each list element in R

I have the following data: col1 = c(rep("a",4),rep("b",8),rep("c",6), rep("d",2)) col2 = sample(-100:250, 20) col3 = cumsum(col2) data = data.table(col1, col2, col3) and data.table: col1 col2 col3 1: a 56 56 2: a 90 146 3: a…
MarekW
  • 41
  • 5
-1
votes
2 answers

Get prevvious value of a column and create vector of cumsum

I have following R code: >a 1 2 3 4 5 I want to create b such that b[i] = a[i] + b[i-1]. Need help, how to do above action in R.
RHelp
  • 815
  • 2
  • 8
  • 23
-1
votes
1 answer

Matlab: cumsum and exhaustive unique element's indexing with greedy perspective

Trying to understand how to manipulate two matrices having the following elements (i ll try to simplify my problem so to be easier to answer) by expanding my previous question: First matrix: 8 2 5 Mat1 = [ 3 7 8 ] 6 5 0…
professor
  • 247
  • 3
  • 12
-2
votes
1 answer

How to do cumulative sum of array for 3 dimensions? (for loop for 3 dimensions)

I have an array of three dimension x[i,j,k]=[[[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]], [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]], [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]], [[1, 6], [2, 7], [3, 8], [4, 9], [5, 10]]] And I need cumulative sum like…
-2
votes
2 answers

Cumulative sum with a reset

I want to use the cumsum function of pandas and reset this cumulative series when a condition is fulfilled. For example i have this df : o values 0 1 4 1 1 4 2 2 2 3 2 5 4 3 1 5 3 …
Pi-R
  • 644
  • 3
  • 10
-2
votes
1 answer

Pandas To datetime & Cumsum Milliseconds

I have a several question. First, I want to datetime in pandas dataframe. like this... 2018/03/06 00:01:27:744 How can I replace this datetime? And Then.. Second.. Time Sensor1 Sensor2 TimeCumsum 2018/03/06…
GrayHash
  • 297
  • 2
  • 9
-2
votes
2 answers

R: Build custom cumsum function in sapply

I'm trying to build a more custom version of cumsum to use on a data.table, but I'm failing at the first step: numbers <- data.table(num=1:10) sum <- 0 cumFunct <- function(n) { sum <<- sum+n return(sum) } numbers[, cum:=sapply(num,…
Oli
  • 317
  • 1
  • 2
  • 9
-2
votes
1 answer

Reverse a Cumulative Column

I want to reverse of this - Calculating YTD totals in Pandas ID month year Fee 68119 February 2015 25 68119 March 2015 25 68119 April 2015 25 68119 May 2015 25 00200 February 2015 50 00200 March 2015 …
Vivek Kalyanarangan
  • 8,951
  • 1
  • 23
  • 42
-2
votes
2 answers

Group together two columns with ID, do the cumulative for two columns

Edit: I wrote the question way to unstructured, let me try again. I want to create two new columns, winner_total_points and loser_total_points to the dataset below. winner <- c(1,2,3,4,1,2) loser <- c(2,3,1,3,3,1) winner_points <-…
Axel Eriksson
  • 105
  • 1
  • 11
-2
votes
1 answer

Pandas: add values to two new columns in table if values in two previous columns are continuous?

So, I was trying to accomplish this in SQL but was advised there would be a simple way to do this in Pandas... I would appreciate your help/hints! I currently have the table on the left with two columns (begin subsession and end subsession), and I…
-2
votes
2 answers

Python: Partial sum of a set in a matrix by columns

I have two large matrices (1800L;1800C), epeq and triax, that have columns like: epeq= 0 1 1 2 1 0 3 3 1 1 0 2 1 1 1 triax= -1 1 3 1 -2 -3 -1 1 2 3 2 1 -1 -3 -1 1 as you can see, triax columns have cycles of positive and negative elements. I…
-2
votes
1 answer

Frequency by Day and Month R

I have a large dataset...60k records covering 63 years of data. I need to produce a plot of mean number of events per day over the 63 year period, resulting in a dataframe like: Date Frequency DDMM 5.2 First question - How can I convert the…
Methexis
  • 2,739
  • 5
  • 24
  • 34
-3
votes
1 answer

cumulative month to date and year to date sum

I am having issues finding a solution for the cummulative sum for mtd and ytd I need help to get this result
andrea
  • 1
-3
votes
1 answer

How can I write my own R cumsum() function?

I am so new in R and want to write my own R cumsum() function. How can I create the function which takes in a length N vector of values to compute cumulative sums. Thanks
1 2 3
53
54