Questions regarding rowsum, R function which gives column sums of a matrix or data frame, based on a grouping variable
Questions tagged [rowsum]
208 questions
0
votes
3 answers
rowSums excluding a particular value in a dplyr pipe without modifying the underlying data frame
I have a data frame of questionnaire data in wide format, with each column representing a questionnaire item.
The data looks something like the following:
df <- data.frame(Q1 = c(1, 4, 2, 3, 1, 1, 4, 4, 1, 2),
Q2 = c(NA, 3, 1, 4, NA,…

DTYK
- 1,098
- 1
- 8
- 33
0
votes
1 answer
Merging rows will defining different parameters for each row being combined in R
I have a dataframe with different parameters in each. I'll like to merge rows using a different set of parameters for each row.
Here is my sameple data ZZ:
ZZ<-data.frame(Name…

Joke O.
- 515
- 6
- 29
0
votes
2 answers
rowsums accross specific row in a matrix
final.marks
# raj sanga rohan rahul
#physics 45 43 44 49
#chemistry 47 45 48 47
#total 92 88 92 96
This is the matrix I have. Now I want to find the total for each subject separately across respective…

rajesh Subramanian
- 11
- 1
0
votes
2 answers
colsum conditions in R?
I have this data that is split by week and would like to change this into monthly and/or quarterly data. Is there a condition that I can use that will sum column data based on dates or weeks? I am unsure how to do it based on weeks given I have data…

ct957
- 37
- 1
- 2
- 8
0
votes
1 answer
Sum across columns in same row using column name R
I have a dataset similar to what is below:
ID | Var1 | Var2 | Var3 | Sum
-----------------------------
1 3 4 7
2 1 2 3
3 3 5 16
I need to create the Sum variable above. I need to be able to…

Adam_S
- 687
- 2
- 12
- 24
0
votes
3 answers
Sum two columns in a new columns in R only if one Na
I want to sum two columns let's say the columns "apinten" and "apmod". I want R to ignore Na if there is Na in only one of the two columns, but I want to report "Na" if the two columns are Na ... For the moment I did it :…

Cyril Forestier
- 11
- 1
0
votes
1 answer
Filter by rows and sum column values
My data looks like
pos year A B
1 2012 1 1
1 2013 1 NA
2 2012 NA NA
2 2013 NA 1
I tried to calculate the percentage difference between A and B for each pos only when both A and B are not NA.
ddply(x, .(pos), summarize, diff =…

D.Z.
- 1
- 2
0
votes
1 answer
Sum of integer columns is double
I don't understand why and how to prevent the sum of two integer columns to be class numeric, type double. Any idea?
Here is a small working example
library(data.table)
set.seed(123)
A <- rnorm(20, 100, 5)
B <- rnorm(20, 50, 20)
NA.A <- which(A…

simone
- 577
- 1
- 7
- 15
0
votes
2 answers
Rolling rowsums in unbalanced panel data in R
I have unbalanced panel data and want to take the rowsum (MRAR) for each observation over the past 36 months as reported in the columns (time-series "dates"):
dput(ER)
NA, NA, NA, NA, NA, NA, NA, -4.91111111111111, NA, NA, -6,
NA, NA, NA,…
0
votes
0 answers
Accessing to columns and rows on a dataframe and summing specific rows based on columns specified in a list
My data are structured in a list (named L) of length 6, so it contains 6 dataframes. I'm correctly accessing the df i want (named D) with: L[[dfname]].
My target is to get the sum of a row identified by a vector from another dataframe (named…

fedezi
- 21
- 4
0
votes
0 answers
If multiple condition not giving output in r
I have a dataframe
df= data.frame(ID=paste(rep("a",7),c(1:7),sep = ""),
col2=c(12,10,1,2,5,10,8),
col3=c(200,150,180,450,100,130,200))
I'm trying to check a combination of those element that sum upto a particular…

Andre_k
- 1,680
- 3
- 18
- 41
0
votes
3 answers
Efficiently get the row.max and row.sum of a Java 2D array
In Java, given a 2D array of double values with dim as 6000*6000, is there an efficient way to query the row max and the row sum?
I am using the data structure double[][] and a two-layer loop to get the row max and sum, but it is not sufficiently…

Huanfa Chen
- 577
- 6
- 15
0
votes
3 answers
Summing elements of numpy array in Python
I have an numpy array
>>> clf_prob.dtype()
array([[ 0.05811791, 0.06526527, 0.06024136, ..., 0.06972481],
[ 0.06093686, 0.06357167, 0.06462331, ..., 0.06999094],
[ 0.08188396, 0.08504034, 0.0820972 , ..., 0.08487802],
…

Andre_k
- 1,680
- 3
- 18
- 41
0
votes
1 answer
Adding multiple elements of a single columns of dataframe in python
dataframe = ax
Col1
0.98 0.076 0.09
0.81 0.01 0.378
0.12 0.33 0.001
I want to add these multiple elements of a single row which are separated by space in python such that my output be like
Col1 Summm
0.98 0.076 0.09 …

Andre_k
- 1,680
- 3
- 18
- 41
0
votes
3 answers
Rowsums conditional on column name
My data.frage looks like this:
VAR1 VAR2 AUS1 AUS2 AUS3 AUS4 ... AUS56 VAR3 VAR4
A D 23 234 34 856 ... 99 0 FCK
B D 55 76 55 36 ... 6456 0 XYC
I'd like R to add a new variable AUS which shows the…

Laubsauger
- 69
- 2
- 9