Questions tagged [column-sum]

In a 2-dimensional matrix, summing up all values in a given column yields the column's column sum.

Having a 2-dimensional matrix with r rows and c columns, the formula for the column sum of column c_x is colSum(c_x) = matrix[0, c_x] + matrix[1, col_x] + ... + matrix[r-1, c_x].

28 questions
21
votes
3 answers

How do I divide matrix elements by column sums in MATLAB?

Is there an easy way to divide each matrix element by the column sum? For example: input: 1 4 4 10 output: 1/5 4/14 4/5 10/14
danatel
  • 4,844
  • 11
  • 48
  • 62
2
votes
2 answers

Stack Based Column Sum in a data frame using R

My existing data frame looks line given below NAV_Date NAV Year Day Units Amount Balance_Units 2013-06-01 282.5 2013 Saturday 3.540 1000 3.540 2013-06-08 279.3 2013 Saturday 3.581 1000 3.581 2013-06-15 276.0 2013…
2
votes
2 answers

Summing a specific vector index

I'm having trouble figuring out how vectors are formatted. I need to find the average height of participants in the cystfibr package of the ISwR library. When printing the entire height data set it appears to be a 21x2 matrix with height values and…
Nick
  • 21
  • 1
2
votes
2 answers

How to add together certain rows within a column in R by unique IDs?

I'm new and sorry if my question is badly worded. I'm working in r and I have table called Rent that might look like this : Rent ID Invoice Payment Paid Date lucy 7/1/2018 100 9/1/2018 lucy 7/1/2018 …
Michael
  • 59
  • 5
2
votes
1 answer

codeigniter - how to add up values in table column

Trying to get the sum of the values entered within a column (af_am_msm) from my table (non_clinical_total_tests). I want to display that total within an html table. My error message is: A PHP Error was encountered - Severity: Notice - Message:…
2
votes
1 answer

Column sum based on conditions

I had a problem when summing columns based on condition. Here, summing columns means d23+d24+d25+d26+..+d31. Below is part of my dataframe. d23 d24 d25 d26 d27 d28 d29 d30 d31 854 -0.60 4.11 8.52 0.90 -7.99 -10.27 -8.32 …
Yabin Da
  • 553
  • 5
  • 11
2
votes
2 answers

Kotlin: Elegant way to sum elements across the rows in matrix?

Given an ArrayList (rows) of ArrayList (elements in a row), is there a better way to obtain a list of sums like (row[0][0] + row[1][0] + .... row[n][0]) except writing a "for" loop?
2
votes
1 answer

Sum of all dynamic columns

Here is what I need to find, Sum all values present in dynamically generated system columns. I have found how to generate dynamically generated columns by using following query. declare @columnnames nvarchar(max) = 'select COLUMN_NAME FROM …
krishna31
  • 113
  • 1
  • 9
2
votes
1 answer

Add a ColSum to vector in r using dplyr

I am trying to add the sum (of all the counts in a specific vector) in my data frame in R. Specifically, I want to keep all the counts and then add a sum at the end. In excel, you would do =sum(A1:A5232). Additionally, I don't know the length of the…
1
vote
1 answer

Get column data sum from FormIO table element

I'm trying to get the column number sum in a table element from FormIO. At the moment I'm doing this with this script: if(data['personesAtesesNoBinari17'] >= 0 || data['personesAtesesNoBinari1631'] >= 0 || data['personesAtesesNoBinari3066'] >=…
Javi
  • 13
  • 6
1
vote
1 answer

Column sum changing name of variables in r

I´m trying to do a column sum using apply and I would like to know if you could give me some advice to understand the best way to repete the same opperation but changing the names of the variables without having to write several lines. I have a…
Javiera
  • 11
  • 1
1
vote
2 answers

Sum column based on condition in another columns in R

I have to sum the values of a column based on an if statement. Here my code: a <- c(1,2,3) b <- c(2,2,3) f <- c(1,2,3) df <- data.frame(a,b,f) df for (i in 1:nrow(df)){ if (df$a[i] == df$b[i]){ w <- sum(df$f) } } My result is 6 while it…
1
vote
1 answer

Dynamic column sum total when adding a row with JS

Can someone help please? I have an editable table with column sum, using HTML and JS. I tried to add a row, it's working but when I enter value on the new row, my total column is not changing dynamically, it's changing only after I use another…
1
vote
3 answers

Vertical column summation in sas

I have the following piece of result, which i need to add. Seems like a simple request, but i have spent a few days already trying to find the solution to this problem. Data have: Measure Jan_total Feb_total Startup 100 …
Sahil Khurana
  • 21
  • 1
  • 3
1
vote
4 answers

create a matrix by seperating an existing matrix into groups(by factor) and applying a function to each sub-matrix

This problem is best addressed through example: The setup x1 <- c(1,4,5,6,7,1) x2 <- c(1,1,2,3,4,1) x3 <- c(3,4,5,6,7,1) x4 <- c(1,2,3,5,7,2) x5 <- c(6,2,3,9,7,2) x6 <- c(5,2,4,3,2,3) x7 <- c(6,4,3,1,8,3) matrix <-…
JC3019
  • 363
  • 1
  • 9
1
2