Questions tagged [rowsum]

Questions regarding rowsum, R function which gives column sums of a matrix or data frame, based on a grouping variable

208 questions
0
votes
0 answers

How to remove singletons and dobletons

My problem is this: A table containing different values and what I need is to eliminate the singletons (rowSums = 1) and dobletons (rowSums = 2) at the same time without need to repeat the steps. Name samp1 samp2 samp3 samp4 A 1.00 …
F.Lira
  • 663
  • 2
  • 6
  • 19
0
votes
3 answers

Need to SUM the column values upto same rowno

I have a scenario, where I am going to show the sum of the column values upto specific row values. where i am giving category A,B and C from subtotal. if subtotal hvs 80, i will give A, and from 81-90 B and 91-100, is set as 100 for example Class …
0
votes
1 answer

Using rowSum and subset to clean data

I am having trouble subsetting a large data frame. I have 5,000 observations and 60+ columns. I want to subset based on ~ 30 columns -- essentially to "drop" any observations where the sum of the values in these 30 columns of interest == 0. A small…
Julia
  • 9
  • 2
0
votes
0 answers

How to merge multiple dataframe columns into one?

I have a dataframe with 21 columns. I want to merge 15 of these columns into one that can be identified as a variable 'Other.' This is my code so far, and I am not having luck in doing this so far, with rowSums it says Error in as.data.frame(y) :…
espop23
  • 77
  • 2
  • 2
  • 9
0
votes
1 answer

Partial Sum of numeric vector by row from data.frame

I'm working on a database with repeated measures, and I need to calculate the sum of a numeric vector by category and remove repetitions. Category Area A 30A 15A 20B 45B 30C 12D 18D …
0
votes
3 answers

row sum average: Elements appears to be zero when compared

I want to find out row sum average but in case zero appears in the row then that particular column should be left when average of the row is done. let it be more clear. i have a matrix say 5 3 4 4 0 3 1 2 3 3 4 3 4 3 5 3 3…
user3804161
  • 45
  • 2
  • 7
0
votes
3 answers

rowSums - error due to array

I am getting crazy due to error message. I used exactly the script but with another matrix and I cannot compute the rowsum anymore. I got this annoying error message: x must be an array of at least two dimension I want to compute the row sum of…
richpiana
  • 411
  • 1
  • 7
  • 16
0
votes
0 answers

Weighted percentage contribution by row in R

I have a matrix of 2 columns. I calculated the percentage contribution of each column by row to the overall using the formula below: B = matrix (c(2,4,3,1,5,7,5,3,8,3,7,3),nrow=6,ncol=2) sweep(B, 1, rowSums(B), FUN="/") This gives the result…
Joke O.
  • 515
  • 6
  • 29
0
votes
1 answer

R : Taking sum of row on a condition in a loop

I have a dataframe which looks somewhat like this : inter_cv_vars <- data.frame( I_Org_ZB1 = rep(0:1,each = 2, len = 20), I_Org_ZB2 = rep(0:1,each = 1, len = 20), I_Org_ZB3 = rep(0:1,each = 3, len = 20), I_Org_ZB4 = rep(0:1,each = 4, len =…
Amit Mishra
  • 33
  • 1
  • 10
0
votes
1 answer

Count number of ones in first two columns in a data frame

Say, I have a data frame as below, having three columns. I would like to create a fourth column whose value is the sum of the number of ones in the first two columns put together An iterative version col1 = c(1,1,1,0,0) col2 = c(1,0,0,0,1) col3 =…
IAMTubby
  • 1,627
  • 4
  • 28
  • 40
0
votes
1 answer

Exclude values within a range for rowsum in R

I'm trying to get the row sums for each row of my dataframe but with a condition. I'd like to exclude all the values that are between -1 and 1 after applying log2. I know how to exclude NAs but I'm confused with excluding actual numbers. My…
abn
  • 1,353
  • 4
  • 28
  • 58
0
votes
1 answer

rowSums of alternating rows in a loop

I have a dataframe called Paperon citations of papers for every year including their publication year as well as some meta stuff (journal, authors). It looks like: Paper = read.table(textConnection("Meta Publication.Year X1999 X2000 X2001 X2002…
MERose
  • 4,048
  • 7
  • 53
  • 79
0
votes
2 answers

R - How to sum objects in a column between an interval defined by conditions on another column

This comes as an application to this question:Sum object in a column between an interval defined by another column What I would like to know is how to adjust the answer if I want to sum the values in B, for ((A[i+1]-A[i]==0) or (A[i+1]-A[i]==1) or…
Nanami
  • 3,319
  • 3
  • 19
  • 19
0
votes
2 answers

R: use a row as a grouping vector for row sums

If I have a data set laid out like: Cohort Food1 Food2 Food 3 Food 4 -------------------------------- Group 1 1 2 3 A 1 1 0 1 B 0 0 1 0 C 1 1 0 1 D 0 0 0 …
Nick Crouch
  • 301
  • 3
  • 14
-1
votes
1 answer

2D Array Row Sum

I have a 2D array in python and I'm trying to add the values in the rows, but I only get the sum from the last 1D array. code: def sum_row(A,n): for i in range(len(A)): s = 0 for j in range(len(A[i])): s = A[i].sum() …
hii
  • 11
  • 5
1 2 3
13
14