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
4 answers

Subsetting using rowsum or rowSums

I am very new to R. I would like to create a list of all possible concentration combinations of a recipe that is comprise of 4 materials. The last line is where I am running into issues. #create a sequence of numbers from 0.01 to 0.97 by 0.01 #(all…
CHansel
  • 11
  • 2
0
votes
2 answers

rowsum across specific columns using dplyr's start_with

I am trying to make aggregates for some columns in my dataset. I took great pains to make the data organized, so I want to use the column names to add across my scales, rather than the index. Here's my data: library(tidyverse) data <- tibble(name =…
J.Sabree
  • 2,280
  • 19
  • 48
0
votes
3 answers

How to assign rowsums of a dataframe in R along a column in the same dataframe

I have the following data frame in R DF1<-data.frame("S"=c("A", "B", "C")) namelist<-c("A", "B", "C") DF1[c("A", "B", "C")]<-c(1,2,3) DF1$B<-DF1$B*2 I have created a new column Sum as follows DF1$Sum<-0 The resulting dataframe is as follows …
Raghavan vmvs
  • 1,213
  • 1
  • 10
  • 29
0
votes
1 answer

Sum many rows with some of them have NA in all needed columns

I am trying to do rowSums but I got zero for the last row and I need it to be "NA". My df is a b c sum 1 1 4 7 12 2 2 NA 8 10 3 3 5 NA 8 4 NA NA NA NA I used this code based on this link; Sum of two Columns of Data Frame with…
Mohamed Rahouma
  • 1,084
  • 9
  • 20
0
votes
1 answer

Trying to find row sums in R using dplyr, then filter out columns

So I thought this would be a little simpler but it's proving not to be the case. I would like to get the row total of each row and filter the rows that have a row total not equal to 0, but since the first column is an identifier I need to only sum…
Johnny Thomas
  • 623
  • 5
  • 13
0
votes
1 answer

Error "The weights don't sum to 1" occurs, but they do sum to 1 (MCDM package for R)

I'm running a sensitivity analysis for a multi-criteria decision model. The model is run in R, using the package MCDM. A key component of the model is that it relies on a user-given set of weights that must sum to 1. I am working with weight…
Savi
  • 49
  • 7
0
votes
1 answer

Finding number of NAs across all columns, row by row, and assigning number to new variable

So I have a dataframe which has multiple columns and many rows. I want to be able to assign the number of NAs across all the columns row by row to a new variable (NACount). Something like this: Col1 Col2 Col3 Col4 NACount A A B NA 1 B…
Keith
  • 103
  • 1
  • 9
0
votes
0 answers

how to sum absolute values of multiple columns in R

I'd like to have the sum of absolute values of multiple columns with certain characteristics, say their names end in _s. set.seed(154) d <- data.frame(a_s = sample(-10:10,6,replace=F),b_s = sample(-5:10,6,replace=F), c =…
Ana
  • 1,516
  • 3
  • 15
  • 26
0
votes
2 answers

Summing rows over varying amount of columns in R

I have a data frame that consists of one row for each user. For each user, I have information on when they first logged on to a website (row 1), and for each day after that (each day is a column) how many times per day they logged in. I would like…
Nina
  • 91
  • 7
0
votes
2 answers

Adding row and column total to pivot table fails

I want to display row and column total. I am using margin=True but the output does not show row total as below code and output: import pandas as pd df2 =…
MGB.py
  • 461
  • 2
  • 9
  • 25
0
votes
2 answers

rowsum based on groupings or conditions in r

I want to do rowsum in r based on column names. I have more than 50 columns and have looked at various solutions, including this. However, this doesn't really answer my question. I have column names such as: total_2012Q1, total_2012Q2,…
Sun
  • 157
  • 11
0
votes
1 answer

RowSums set of columns if multiple columns conditions are met

I wish to RowSums the total number of columns (in this case years of education) but only if a value (the age of respondents) is greater than a certain number (>=16). The number of columns is greater than the example (up to 13 for age and education)…
Nicola
  • 446
  • 7
  • 17
0
votes
2 answers

dplyr row sum on selected rows

I have the following data: library(dplyr) library(purrr) d <- data.frame( Type= c("d", "e", "d", "e"), "2000"= c(1, 5, 1, 5), "2001" = c(2, 5 , 6, 4), "2002" = c(8, 9, 6, 3)) I would like to use rowsum and mutate to generate a new row…
Mrmoleje
  • 453
  • 1
  • 12
  • 35
0
votes
3 answers

How to sum every nth (200) observation in a data frame using R

I am new to R so any help is greatly appreciated! I have a data frame of 278800 observations for each of my 10 variables, I am trying to create an 11th variable that sums every 200 observations (or rows) of a specific variable/column (sum(1:200,…
esg16
  • 11
  • 1
  • 1
0
votes
1 answer

Search in row for a certain value and report the date

Ciao, Here is my replicating…
bvowe
  • 3,004
  • 3
  • 16
  • 33