## Misunderstanding of functions in R

I have a vector p <- seq(0,1,length=11) That I want to use as the independent variable in the summation If I craft a function that codes the summation by hand f <- function(a){ a^0*(1-a)^5+a^1*(1-a)^4+... } and pass it p, then I get t...
more »

2017-10-04 22:10 (3) Answers

## How to sum multiple dataframe's variables by month

I have got a very similar issue addressed here how to sum data by month and store them in the first day of the month The only thing that differs from the above post is that my real data.frame has got 300 variables that need to be grouped and summed...
more »

2017-09-28 10:09 (1) Answers

## numpy array sum function

Let's say I have two one dimensional arrays, a and b, of length say n+1 and m+1. I want c to be the an array of the same length as b, with elements equal to the sine of the sum of all a elements to the power b. Written in pseudo code below. c = sum...
more »

2017-09-26 16:09 (2) Answers

## Select and show according to the year/monts

can you help me to select, and sum all the values from the table, and show them according to the months/this year? Table looks as follow" | ID | value | reg_date | | 1 | 2 | 2017-01-11 02:26:22 | | 2 | 2 | 2017-03-12 12:22:23 ...
more »

2017-09-21 11:09 (3) Answers

## Write a method to work out the sum of the first n odd numbers

First of all let me say I am quite new to programming its been my second week since I started so if you see any bad practice or error in code please accept my apologies. I want to print sum of first n odd numbers. But so far I can only do the sum of...
more »

2017-09-21 10:09 (8) Answers

## Alternating series using Haskell

I am trying to use Haskell to read in a list and perform an alternating series, so starting with the first element adding every other and subtracting every other from the second element. For instance [1, 2, 3, 4] would be 1-2+3-4=-2. I thought I had...
more »

2017-09-14 21:09 (2) Answers

## Different amounts in payment script

I have a payment script. now it works with fixed amounts, for example if the total is 1000 USD and my client wants to pay me with five installments for 200 USD each quota is working perfect. But now I need to know how can I change the code (pdo + MyS...
more »

2017-09-09 03:09 (0) Answers

## Haskell - Sum of the differences between each element in each matrix

I am very new to Haskell (and functional programming in general) and I am trying to write a function called "profileDistance m1 m2" that takes two matrices as parameters and needs to calculate the sum of the differences between each element in each ...
more »

2017-09-08 18:09 (1) Answers

## Sum of the number of event from each date interval in R

I have a actual data with massive time intervals, i.e. event_start date (say 2014-10-1), event_end date (2014-12-1), and I also have a reference data set which keeps the whether there is a specific event happened within each day, for example: if ther...
more »

2017-08-30 13:08 (2) Answers

## numpy sum axis intuition

I've always thought that axis 0 is row-wise and 1 is column-wise. row-wise (axis 0) ---> [[ 0 1] [ 0 5]] ↑ | column-wise (axis ...
more »

2017-08-26 05:08 (0) Answers

## R: calculate total score over various rows with class 'factor'

I'm analysing a dataset where I have conducted a questionnaire. The questionnaire had a 5-point likert scale, 1 corresponding to 'very often' and 5 corresponding to 'never'. I have the single answers of every case to 50 questions (e.g. bb1, bb2, bb3 ...
more »

2017-08-24 14:08 (0) Answers

## Django Group_by Date with Sum Data

I need to combing many acct_id's records into a single summary grouped by the "month" field. All the other data like "value" and "cash_in" need to be Sum() class Cashflow ( models.Model ): acct_id = models.ForeignKey ( Acct ) month = models.D...
more »

2017-08-19 08:08 (1) Answers

## Calculate sum based on different dates

I'm new to Stackoverflow and I need your help for this problem. I have a table (sql 2014 and use vb.net) like this: ID Codfisc Dal Al 1 xxxxxxx 2017/08/08 2017/08/14 I have developed this code: Dim a As Date = Date.Parse(TextBox2.Te...
more »

2017-08-15 00:08 (0) Answers

## conditional sum with dates in column names

Want to calculate conditional sum based on specified dates in r. My sample df is start_date = c("7/24/2017", "7/1/2017", "7/25/2017") end_date = c("7/27/2017", "7/4/2017", "7/28/2017") `7/23/2017` = c(1,5,1) `7/24/2017` = c(2,0,2) `7/25/2017` = c...
more »

2017-08-14 16:08 (3) Answers

## Scipy Sparse Cumsum

Suppose I have a scipy.sparse.csr_matrix representing the values below [[0 0 1 2 0 3 0 4] [1 0 0 2 0 3 4 0]] I want to calculate the cumulative sum of non-zero values in-place, which would change the array to: [[0 0 1 3 0 6 0 10] [1 0 0 3 0 6 1...
more »

2017-08-03 21:08 (0) Answers

## VBA Sum a Range of Cells

I'm attempting to write a simple VBA macro that will take the active cell's column and the user's input to add a range of cells on a single row together. The range is calculated by adding the integer the user inputs to the active column and that is t...
more »

2017-08-03 17:08 (1) Answers

## Fastest way to calculate the sum of specific regions of an array

Given the following data (in python 2.7): import numpy as np a = np.array([1,2,3,4,5,6,7,8,9,10,11,12,14]) b = np.array([8,2,3]) I want to get the sum of the first 8 elements in a, then the sum of the 9 and 10 element and in the end the last 3 (ba...
more »

2017-08-03 12:08 (5) Answers

## Sum values from specific day forward in a week in Excel

This is my first post here, I'll try to be as clear as I can. I need to sum all the hours worked from day 1 to last day of the month. The data is arranged by week ending dates, and then the amount of hours worked per day in separate columns. Data ...
more »

2017-07-31 18:07 (0) Answers

## Large Numpy Scipy CSR Matrix, row wise operation

I want to iterate over the rows of a CSR Matrix and divide each element by the sum of the row, similar to this here: numpy divide row by row sum My problem is that I'm dealing with a large matrix: (96582, 350138) And when applying the operation fr...
more »

2017-07-28 14:07 (2) Answers

## Summarize data and keep date column value

I asked a similar question before and got an excellent answer, but needed some more guidance on the topic of summarizing and dates. Summarize and count data in R with dplyr Goal: In my new dataset i have column with dates, when the event occured. W...
more »

2017-07-26 10:07 (2) Answers

## Is it possible to skip NA values in "+" operator?

I want to calculate an equation in R. I don't want to use the function sum because it's returning 1 value. I want the full vector of values. x = 1:10 y = c(21:29,NA) x+y [1] 22 24 26 28 30 32 34 36 38 NA x = 1:10 y = c(21:30) x+y [1] 22 24 26 28...
more »

2017-07-25 20:07 (5) Answers

## How can i assume that my date when has a value is equal to 1 and total?

The date if has value i want it equals to 1 and add it all in total heres my sample fiddle My sample fiddle html \$(document).ready(function(){ \$('[id^=total]').on('change',function() { var total = 0; \$('[id^=total]').each(f...
more »

2017-07-25 07:07 (1) Answers

## shorten code range array elements

How can I shorten this code? I also tried SUM on a range of array elements but that didn't worked because I don't know the correct syntax. Thanks in advance. Workbooks("items.xlsm").Sheets(1).Cells(r, 107).Value = _ arr(r, 4) + arr(r, 5) + arr(r, 6)...
more »

2017-07-22 20:07 (1) Answers

## SUM numbers, but when 0, add 8 instead

I'm trying to write a SUM(IF(zero, add 8), A1:G1) kind of excel function. What it should do: If the cell contains a number, add that number to the sum. If the cell contains a number = 0, add 8 to the sum. if the cell is empty, add nothing to the su...
more »

2017-07-18 12:07 (3) Answers

## Add together n-dimensions in a three dimensional array in R

everyone! I have a very straight problem. I have a three dimensional array called w, like this: > w , , 1 [,1] [,2] [,3] [1,] 0.5 0.5 0.5 [2,] 0.5 0.5 0.5 , , 2 [,1] [,2] [,3] [1,] 0.1 0.1 1.0 [2,] 0.5 0.5 0.5 Now, it i...
more »

2017-07-17 12:07 (1) Answers

## How to sum every element in a numpy array divisible by 5 using vectorization?

I am looking for a vectorization method for summing all elements of a numpy array that is evenly divisible by 5. For example, if I have test = np.array([1,5,12,15,20,22]) I want to return 40. I know about the np.sum method, but is there a way to...
more »

2017-07-11 17:07 (1) Answers

## How to ignore values when using numpy.sum and numpy.mean in matrices

Is there a way to avoid using specific values when applying sum and mean in numpy? I'd like to avoid, for instance, the -999 value when calculating the result. In [14]: c = np.matrix([[4., 2.],[4., 1.]]) In [15]: d = np.matrix([[3., 2.],[4., -999....
more »

2017-07-04 21:07 (2) Answers

## Dixon & Price function in Python - summing elements of a list together with index number

Consider the Dixon & Price function here. How can I write this function in Python? I tried def dixonprice(v): # v is a input vector v2 = v.pop(0) # since we need the sum from the second element onwards return (v[0]-1)**2 + sum(*...
more »

2017-06-29 19:06 (2) Answers

## numpy.sum not returning expected value

I'm working through project euler problems. 'Find the sum of all the primes below two million' I've built a prime checker that I think is pretty fast - any advise on how to improve would be great too. But, what I've spent the last 30mins working ...
more »

2017-06-25 06:06 (1) Answers

## I applied sum() on a groupby and I want to sort the values of the last column

Given the following DataFrame user_ID product_id amount 1 456 1 1 87 1 1 788 3 1 456 5 1 87 2 ... ... ... The first column is the ID of th...
more »

2017-06-25 05:06 (2) Answers

## Total range of cells in multiple workbooks from a file

What I am trying to do is create a master file that has the totals of all of the files in a workbook. However, I do not have the files that need to be totaled, yet. It is for an expense report, my team will fill out their expense reports and save th...
more »

2017-06-16 23:06 (1) Answers

## dplyr: sum inside consecutive mutate

library(dplyr) tib <- tibble(a = c(1,2,3)) The following work as expected: tib %>% mutate(b = a^2, c = sqrt(b)) # A tibble: 3 x 3 a b c <dbl> <dbl> <dbl> 1 1 1 1 2 2 4 2 3 3 9...
more »

2017-06-16 21:06 (1) Answers

## How to sum python pandas dataframe in certain time range

I have a dataframe like this df order_date amount 0 2015-10-02 1 1 2015-12-21 15 2 2015-12-24 3 3 2015-12-26 4 4 2015-12-27 5 5 2015-12-28 10 I would like to sum on df["amount"] based on range from...
more »

2017-05-24 17:05 (5) Answers

## Excel SumProduct with if Statement in a cell.

I have a basic problem in Excel. I have a row with names and one with numbers. I try to find what is the sum of these numbers for a special name. ex. A B Apple 12 Apple 12 Kiwi 9 Apple 4 Banana 51 Kiwi 12 Bana...
more »

2017-05-24 06:05 (2) Answers

## MYSQL has 2 tables. Same dates total. Compare and subtract dates

​tablo1 tablo2 -------------------------- ------------------------------ fiyat1 tarih1 fiyat2 tarih2 ---------- ------------ ----------- ----------- 1200 ...
more »

2017-05-21 20:05 (1) Answers