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
1
vote
1 answer

Choose rows in which the absolute value of subtraction is less a specified value

Let's say I have this dataframe: ID X1 X2 1 1 2 2 2 1 3 3 1 4 4 1 5 5 5 6 6 20 7 7 20 8 9 20 9 10 20 dataset…
Gabriel G.
  • 555
  • 1
  • 3
  • 13
1
vote
2 answers

R: sum largest n rows into a column

I have a data frame that looks like this: df <- tibble(trans_id = c(1:5), name = c('A', 'B', 'C', 'D', 'E'), Yr2020 = c(100, 200, 300, 400, 500), Yr2019 = c(10, 20, 30, 40, 50), Yr2018 = c(1, 2, 3,…
1
vote
3 answers

Faster code for changing values per row to rowsum-1 where value is 1

In R, I have a large dataframe (23344row x 89 col) with sampling locations and entries. value 1 means: object found in this sampling location value 0 means: object not found this sampling location To calculate degrees/connections per sampling…
1
vote
1 answer

Sum rows at specific column intervals

I have a large data frame of 1129 rows and 4662 columns. I want to sum the row values in a data frame at intervals of every 3 columns, and then return 1 for each of these sums if the row sum every 3 columns was >0, or return 0 if the sum<1. I have…
AnnK
  • 189
  • 1
  • 10
1
vote
1 answer

how to make row sum data frame in pandas?

i have data frame as follows and i wanna make a row sum new dataframe and a,b,c,d column values is string. name a b c d aa. 10,000 1,000 1,000 1,000 bb. 10,000 1,000 1,000 1,000 cc. 10,000 …
jerry han
  • 425
  • 4
  • 15
1
vote
1 answer

row and column matrix sum in R by group

I have a matrix matrix with two level groupings as illustrated in the row and column names. UKC1_SS1 UKC1_SS2 UKC2_SS1 UKC2_SS2 UKC1_SS1 1 2 3 4 UKC1_SS2 5 6 7 …
et_
  • 179
  • 8
1
vote
1 answer

Optimize R code for row operations on ternary data frame

Problem I have this function that I need to make it go faster :) if (length(vec) == 0) { # first case count = sum(apply(df, 1, function(x) { all(x == 0, na.rm = T) })) } else if (length(vec) == 1) { # second case count = sum(df[, vec],…
John
  • 359
  • 4
  • 19
1
vote
2 answers

Replace a row value with sum of other rows when conditions are met

I am trying to work out how sum rows based on multiple conditions, but retain all the rows in my data frame, so only those meeting a condition have the summed value, all others have the original value (from a column called iresult_posPPP). I have…
Megan Critchley
  • 105
  • 2
  • 9
1
vote
1 answer

Applying the same function on several pairs of variables

I'm conducting an analysis on the properties of multiples items. To do so, I need to compute scores (mean or sum) of two variables for each items. It's easy to do it for a single item but I can't find a way to do it automatically for all of…
Matthuit
  • 23
  • 3
1
vote
1 answer

rowsum works independently, but not when inside a server function

When using rowsum to summarize values by team outside of a function it works, but when put inside a server function for a dashboard, it is returning the max values. I have been going between rowsum and…
Rob
  • 31
  • 4
1
vote
1 answer

How to sum columns by unique row values while collapsing other columns?

I have a data set with sales numbers from individual items ordered on various dates. All items in a particular order share the same ID. I want to calculate order totals (i.e. sum of sales for all items in a particular order), while preserving the…
1
vote
1 answer

R - how to subtract with rowsum

my dataframe looks like this. df <- read.table(text=" column1 column2 column3 1 3 2 1 1 3 2 1 ", header=TRUE) I need to subtract last 2 columns from first. For…
Sklenicka
  • 595
  • 2
  • 4
  • 16
1
vote
1 answer

calculate sum of values in dataframe based on values in other columns

I have a dataframe in R in which values correspond to value estimates and their margin of error (MoE). Column names consist of a pattern, an indicator character (e = estimate, m = margin of error) and an ID that matches estimate and margin of…
1
vote
1 answer

Sum up specific rows for each column

I'm sure my problem is easy to solve unfortunately I can't come up with a simple solution for my self. I want to sum up certain rows of a dataset for each column. My dataset looks like this: GIVN MICP GFIP -2 0.01 0.02 0.01 -1 0.03 -0.01 …
M.Berns
  • 11
  • 2
1
vote
1 answer

Create an indicator variable in SparklyR when all the variables are missing

I am trying to use rowSum in sparklyr to create an indicator variable where all the variables are missing but it seems that rowSum doesn't work in sparklyr. I have to write the name of all the variables in is.na() function like below which is…
Rio
  • 398
  • 2
  • 15