Questions tagged [sum]

1

votes
3

answer
80

Views

Generate lexicographic series efficiently in Python

I want to generate a lexicographic series of numbers such that for each number the sum of digits is a given constant. It is somewhat similar to 'subset sum problem'. For example if I wish to generate 4-digit numbers with sum = 3 then I have a series like: [3 0 0 0] [2 1 0 0] [2 0 1 0] [2 0 0 1] [1 2...
Aman_X
1

votes
1

answer
29

Views

Getting the count of a value in a column

I'm trying to clean up a large data set. I have code that will return what the unique values are of a column in a data table in R. But when I go to get the count for how many times a specific value occurs, I get an 'NA.' Any help is much appreciated. > RtpStateBitfieldunique RtpStateBitfielduniqu...
1

votes
2

answer
59

Views

Sum columns of a Spark dataframe and create another dataframe

I have a dataframe like below - I am trying to create another dataframe from this which has 2 columns - the column name and the sum of values in each column like this - So far, I've tried this (in Spark 2.2.0) but throws a stack trace - val get_count: (String => Long) = (c: String) => { df.groupB...
van_d39
1

votes
2

answer
40

Views

Get Sum for the column based on a condition

I am working on a SQL Query. Query is something like below: Select a.field1, b.field2, c.field3, c.field4, b.filed5, a.field6, d.field7 from a Inner join b on a.field1 = b.field1 right join c on b.field2 = c.field3 left join d on d.filed3 = a.field1 where some conditions; The output of the a...
ging
1

votes
1

answer
51

Views

how to calculate the sum of elements other than the specified indices?

I have a 3*3 array of values array([[20, 10, 30], [35, 45, 25], [15, 25, 35]]) I want to create a function where, when I pass a number argument it should sum all the rows and column elements smaller than the elements which fall on the number. def sum_con (ar,a): y=a-1 z=ar[0][0]+ar[0][1]+ar[1][0]+a...
user10573543
1

votes
4

answer
81

Views

Scala <collection>.reduce strange behaviour on generic types

I've been wondering, why this piece of code won't compile? Is there a way in Scala to create method/func that is generic parametrised and allows for such operation like 'reduce'. Is this behaviour having anything in common with type erasure or is it something else? I would love to see broad explan...
dreamsComeTrue
1

votes
2

answer
33

Views

MySQL complex query - SUM over several databases using UNION ALL and internal JOINs

I want to calculate a SUM over several databases using UNION ALL and internal JOINs. The MySQL user has the permissions to access all databases relevant. Here is my SQL query code so far: SELECT SUM(summen.OP1OPVerfahren = '0') AS 'Keine Operation durchgeführt', SUM(summen.OP1OPVerfahren = '1') AS...
mtjmohr
1

votes
1

answer
58

Views

javascript reduce function sum of all array values

for (var j = 0; j < l; j++) { aa = (j*5)/12/100; const arr = [ { x: aa } ]; const result = arr.reduce( ( sum, { x } ) => sum + x , 0); console.log( result ); } I have tried to sum of all output numbers using javascript reduce. But, counldn't able to achieve the desired output. This aa variable retur...
Karuppiah RK
1

votes
1

answer
40

Views

Double Variable Summation

So I've been attempting to do double summations on RStudio for awhile and I'm getting nowhere fast.... Does anyone know how to solve equations such as these: So far, the code I did for the first summation is as followed: IndexStart = 1 i = seq(IndexStart, 17, 1) j = seq(IndexStart, 13, 1) resultb =...
Kray
1

votes
2

answer
32

Views

Trying to sum a groupBy value in Laravel 5.5

I have this code suggested to me. I am trying to sum the stock_in_qty and stock_out_qty. $warehouse1stocks = Warehouse1stocks::select( 'order_item_id', Warehouse1stocks::raw('SUM(stock_in_qty) as stock_in_qty'), Warehouse1stocks::raw('SUM(stock_out_qty) as stock_out_qty'))->groupBy('order_item_id')-...
Lito
1

votes
2

answer
22

Views

Create a matrix using the common information in two lists

I have two large lists in the same structure of the toy examples shown in this question. dput(head(list1)): list(FEB_games = list(GAME1 = c('Stan', 'Kenny', 'Cartman', 'Kyle', 'Butters'), GAME2 = c('Kenny', 'Cartman', 'Kyle', 'Butters')), MAR_games = list(GAME3 = c('Stan', 'Kenny', 'Cartman', 'Bu...
Krutik
1

votes
1

answer
34

Views

Keep elements in list whose digits add up to a certain value

From a list find out those values whose addition makes 9 aList=[81,26,27,19,108] output, 81(because: 8+1),27(because: 2+7) and 108 (because:1+0+8) I tried 2 approaches: 1st approach: I could not find a way to get the value, just get the sum s=[81,18] sum=0 for l in s: while l: l,dig=divmod(l,10)...
Sheikh Rahman
1

votes
1

answer
5.1k

Views

Getting sum of multiple columns and calculate each row's ratio

Below, is the schema of my brand_of_items table. For simplicity, shown here with two columns: id (primary and AI), symbol (varchar 50, unique) Table - brand_of_items id symbol 0 a 1 b 2 c .. .. 10 j Below, is the schema of my items_of_brand. Table - mainIndexQuantity id brand_of_i...
mkk700
1

votes
1

answer
44

Views

Creating a bar chart in R from data in a file

First I have created two vectors and put them together Vectors: VektorLHI and VektorRHI sumLHIundRHI
Silvia
1

votes
0

answer
158

Views

Laravel: Average of percentage

I have two numbers that I get from relationships tables and I calculate percentage like this: $safe_voters = AddMember::with('settlement')->whereHas('settlement', function($query) { $query->where('reon_id', '1'); })->where('town_id', Auth::user()->town_id)->count(); $members = AddMember::with('settl...
Nenad M
1

votes
0

answer
428

Views

Pivot Table Calculated Field to Avg the Sums totaled

Need this to average = 7.41 But this happens when I use AVG I am trying to calculate the daily average of each employee based on the number of days worked. I already used a pivot table to calculate the daily total hours of each employee per day but I cannot figure out how to get the pivot table to...
Lord Byronius
1

votes
2

answer
47

Views

R Sum duplicated rows in another data frame

I have a two data frames like this dat1 = data.frame('name' = c('Peter', 'Tom', 'Peter', 'Peter', 'Tom'), 'adress' = c('str1', 'str2', 'str1', 'str2', 'str3'), 'product' = c('prod1', 'prod1', 'prod2', 'prod3', 'prod2'), 'val' = c(1,2,3,4,5)) dat2 = data.frame('name' = c('Tom', 'Tom', 'Peter', 'Peter...
WinterMensch
1

votes
1

answer
43

Views

Grouping Daily data into Weekly data but incorrect grouping when year changes

I have a basic table with daily dates and numeric value for each day. However, after the necessary filters, some dates are missing. I would like this daily data (while missing random days of the week) grouped weekly where beginning of the week would be sunday and ending of the week would be saturday...
Nick Momin
1

votes
1

answer
717

Views

Sum Column in Table to variable

I'm trying to sum up a column of a table in a word document. It's 3 column table, the length depends on the document. What I'm doing in the macro is the following: I want to sum up the numbers in column 2. Then I'm adding some certain lines (headings in first column, no numbers in column 2) and chan...
mhammer
1

votes
0

answer
109

Views

Maximum submatrix (2D) by ignoring at most one element

I know the algorithm to find the maximum 2D submatrix is O(m^2*n) with the use of Kadane's algorithm, where m is the columns and n is the rows. But is there an algorithm for finding the maximum 2D submatrix if we have to ignore exactly 1 element in the entire matrix (i.e. we would change its value t...
Alex Borgue
1

votes
1

answer
30

Views

mysql update and set sum value of last 8 hours of the current row

Hi I would like to count the sum of chat_duration from 8 hours ago of the current data I have : agent text start_time datetime end_time datetime chat_duration bigint and i need to insert the calculation result into past8_hours_chat_duration so when i have : +----+--------+------------+-...
blackpass
1

votes
2

answer
57

Views

MySQL SUM, join and union 4 tables

I have 4 tables with similar column name: Table 1 : simp_wajib id anggota nilai 1 nama1 100 2 nama2 100 3 nama1 100 Table 2 : simp_pokok id anggota nilai 1 nama2 100 2 nama3 100 3 nama1 100 Table 3 : simp_sukarela id ang...
user1991131
1

votes
1

answer
596

Views

Remove Duplicates and Sum Formula

I have a set of data that will change so I need a formula to dynamically get a result. From this set of data I end up with two columns, Dates and Amounts, like the following: What I need is to be able to remove the duplicates from the Dates column, while summing the corresponding amounts. So each un...
LaG
1

votes
0

answer
67

Views

how to write this sum of series in Matlab?

how to write this summation in matlab if k=1,..n, and stored at each iteration of k ,i.e Edit I tried to use the solution in symbolic clear;clc h=0.1; x=0:h:2;n=10;m=3; w = @(i,j,k) (-1)^(i+j)*cos((j*pi/h)*(x-x(k))); syms I J J=1:m; for k=1:n f(k)=symsum(symsum(w(I,J,k), J, 1, I), I, 1, m); end but...
workwolf
1

votes
1

answer
11

Views

Summing up of corresponding elements of two arrays or more

Enter a number: 10 Even Numbers: 0 2 4 6 8 10 Odd Numbers: 1 3 5 7 9 Prime Numbers: 2 3 5 7 Sum : 3 8 14 20 17 10 i wanted to sum up the corresponding elements of the array like above what should i do???
Ali Uzair
1

votes
1

answer
21

Views

SUM datas after a GROUP_CONCAT with mySQL

I'm using phpMyAdmn and I've this query in mySQL: SELECT BIL_Date, BIL_Rate, BIL_Quantity, GROUP_CONCAT(COALESCE(STX_Amount, '0')) AS ApplicableTaxesRate FROM ___BillableDatas LEFT JOIN ___SalesTaxes ON FIND_IN_SET(STX_Id, BIL_ApplicableTaxes) > 0 WHERE BIL_HotelId='cus_CNHLMiMOzP5cuM' AND BIL_Booki...
1

votes
1

answer
555

Views

Warning numerical expression has >1 elements: only the first used

I have a dataset as follows: Apr May Jun Jul Aug Sep Oct Nov b 1.0 9.0 4.0 5.3 6.4 3.4 2.5 4.3 2 5.0 6.0 9.0 2.3 5.8 2.3 6.5 5.2 3 8.0 4.0 6.0 0.7 5.2 1.2 2.2 6.1 4 2.0 2.0 2.0 2.0 2.0 2.0 2.0 2.0 7 3.2 3.2 3.2 3.2 3.2 3.2 3.2 3.2 8 4.4 4.1 5.1 6.1 7.1 8.1 9.1 6.8 6 5.6 5.0 3.2 4.2 5.2 1.2 2.2 3.2 5...
Albert Rajan
1

votes
2

answer
62

Views

SQL Server convert sum of column with multiple conditions into new column of same conditioned data

I have a table of golf data. Each golfer has a final score (round_score column) for each round of a given tournament. I want to add all of the round scores up for each golfer and store it in the final_score column. I want this final_score number to stay the same for all rows for that golfer for a to...
Joey Weinberg
1

votes
2

answer
37

Views

Sum up existing vectors and ignoring missing ones

I´m trying to sum up some vectors within a function. Depending on my input, some of the vectors might be created or not. For example, I have vectors A, B, C and D: A
Ana Antunes
1

votes
0

answer
60

Views

Sum values with same id from a list of ids

I'm totally a begginer trying to get this done. I get a list of ids from a query as 1,2,3,4... then I need to SUM the values of a column named 'total' where the id includes one of the ids listed. //Total quoted //$array_quos = $row3['quo_list']; $array_quos = explode(',', $row3['quo_list']); foreach...
Vhvd
1

votes
1

answer
40

Views

Create Cumulative Recurring SUM in MySQL for Last “x” Days

My business sales run through a very unique annual cycle based on seasons throughout the year. I can't get a sense of my growth from week to week, or month to month. What I really need is a running total showing the last 365 days -- every day. When I span that across an entire year, I can really see...
Ryan Dahl
1

votes
1

answer
27

Views

Comparing 2 Arrays with sum values

I have an Array filled with sum values of the numbers 1 to 10 and in a for loop i want to check the array for duplicates but these values are e.g. 00034 1 which are 2 numbers so the error message i get is 'too many arguments' how can i change it? Code: while [ $k -le 10 ] do #the line below is the p...
jonas
1

votes
0

answer
106

Views

Sum Amount from Datagridview with Other Textbox and Show it Automatically

Screenshot Hi. I need help from you guy. How do I calculate or sum all the value into the last textbox. I put number in my picture just want to explain what I need here. I put some amount to calculate GST and show it to Total Legal Fees textbox. After number 1, I put temporarily amount just to put m...
Thoiruddin
1

votes
0

answer
54

Views

How to do cumulative plots and which statistical test is better?

I need to do some cumulative plots in R, but I really don't know what to use. I have data like the one below. I want to do some graphs, like shown in the images (below the links). The first showing me that for example 80% of the stops happen when Q is X value. The second one starting from the excee...
ac93
1

votes
0

answer
21

Views

Add a different cell & formula for each row in parsed table

I'm currently parsing specific columns of a table via simple_html_dom. Which works fine. I now want to add an extra column after that group with a calculation-formula for each row. It is also important that it works with various row-numbers, cause each table could have a different amount of rows. It...
Chris
1

votes
2

answer
37

Views

Efficient merge-product-sum with Pandas

Consider two dataframes where the Z column contains integers (although we can also think of it as just containing values from a discrete set), df_1: A | B | Z | PROB --+---+---+----- . | . | . | . . | . | . | . . | . | . | . and df_2: C | D | Z | PROB --+---+---+----- . | . | . | . . | . | . |...
rwolst
1

votes
0

answer
44

Views

Multiple condition sum with '%_total'

I am aiming to produce code that generates an independent total check. As per the below table: column1 Column2 Column3 value independent total check A B c1 10 Null A B c2 11 Null A B...
Mr Nemo
1

votes
0

answer
44

Views

Sympy codegen: summed indexed functions

I'm struggling with what seems to be a simple problem in the python sympy module. Thus I suspect that I have misunderstood something - I hope you can help me. My problem revolves around: sums of vectors (or at least indexed parameters), derivatives of these with respect to a specific matrix element...
user9637844
1

votes
0

answer
94

Views

Xpath Sum NAN-Result - change empty cells to “0”

I am trying to sum specific columns of a table using Xpath evaluate. It works great if all cells contain numbers. But as soon some cells of that column are empty, I'll get 'NAN' as result. So, I really need a solution which handles empty cells as a number or '0'. This is my current code, e.g. for...
Chris
0

votes
1

answer
19

Views

Cum count on a pandas df

I am trying to return a running count to a separate column in a pandas df. There are two columns in the df below. When the integer increases I want to return an increased count to a separate column that is relative to the Val Column. import pandas as pd d = ({ 'Val' : ['Foo','Bar','Foo','Foo','Foo',...
jonboy

View additional questions