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
1 answer
Rolling rowsum over existing data frame with NAs in r
Given the data frame:
df1 <- data.frame(Company = c('A','B','C','D','E'),
`X1980` = c(NA, 5, 3, 8, 13),
`X1981` = c(NA, 12, NA, 11, 29),
`X1982` = c(33, NA, NA, 41, 42),
`X1983`…

Connor Uhl
- 75
- 1
- 9
0
votes
1 answer
Using a specific column's values to subtract from other rows but the column index moves between files in R
Data
I also have the total number of cancer patients (case_totals) and non-cancer patients(control_totals) which in this case is 100 and 1000 respectively.
Variant Cancer IBD AKI CKD CCF IHD
A1 0 5 4 0 0 4
A2 0 8 5 …

tacrolimus
- 500
- 2
- 12
0
votes
2 answers
Is there a way to sum specific rows of a column?
A sample picture attached
The sample dataset file
I have a dataset (please see the attached file), in which I wish to sum the numeric column 'tdiff' based on a specific criteria, e.g. row (1 + 2), row (3 + 4) but not row (11,12,13,14).
I have tried…

Pranav_b
- 19
- 8
0
votes
1 answer
Simple way to pipe rowsums
I have the following data frame (showing a head sample)
dput(sample)
structure(list(VR1 = c(NA, NA, 1L, NA, 0L, NA), VR2 = c(NA,
NA,
NA, NA, NA, NA), VR3 = c(NA, NA, 0L, NA, 0L, NA), VR4 = c(NA,
NA, 1L, NA, 0L, NA), VR5 = c(NA, NA, 1L, NA, 1L,…

Daniel Ortiz
- 79
- 6
0
votes
2 answers
How do i calculate row sums based on the the row value across partial matched column names in R
My original data has over 30, 000 rows and 100 column.This is an example:
dataset
df <- data.frame(Outcomes= c(3, 4, 5, 6),
ADMDATE_3=c(10,7,9, 7),
ADMDATE_4=c(4,10,6,9),
ADMDATE_5=c(2, 11 ,8,8),
ADMDATE_6=c(4.5,7,9,12))
My expected results is…

lesa Bee
- 51
- 1
- 5
0
votes
0 answers
How do I total each row but only using certain columns to create a new column?
I have a data set that deals with hr data. Each row is an employee id and the columns represent scores on questions they were asked.
I want to total the scores on all Common and Tech questions(theres 39 Common Questions and 39 Tech Questions)…

Kathryn Black
- 13
- 2
0
votes
4 answers
if there an R function to sift out all numbers from a row
I am working on a project and for each observation there is a comment column. Within that column it says how long the person stayed in a certain location. Some comments say "2 nights in A, 2 nights in B." As of right now I am only able to filter out…

lbevs
- 11
- 1
- 3
0
votes
1 answer
Any suggestions to implement filter within mutate using dplyr or rowsums with all missing cases
Psychologists work with likert scales almost all the time and let's say I have this dataset:
data <- data.frame(x1 = c(NA,2,4),
x2 = c(NA,3,2),
x3 = c(NA,6,NA))
I would like to use RowSums only if X1, X2, and…

Luis
- 1,388
- 10
- 30
0
votes
2 answers
R Tidyverse - Identify proportion of select columns meeting criteria
I have data like this:
x1 = seq(0, 2, length=5)
x2 = seq(1, 2, length=5)
x3 = seq(0, 1, length=5)
df = data.frame(rbind(x1,x2,x3))
I would like to obtain the proportion of specific columns (based on the name) that have a value less than 1. The…

Jason Schoeneberger
- 83
- 1
- 7
0
votes
1 answer
Count of crashes and injuries?
I have a dataset from dot.gov website that I have to analyze as part of our school project. It contains a lot of information, but I am just focusing on crashes and injuries. How do I count the number of crashes or injuries from the year 2007-2014…

Pinaypy
- 37
- 1
- 8
0
votes
1 answer
Sum rows by selected columns specified by a character string in R
What I have: A large file of 1451 rows and 4663 columns with values 0, 1 and NAs. The row names represent sites and the columns names the date of the survey. I would like to sum rows using specific date intervals, that is to sum specific columns…

AnnK
- 189
- 1
- 10
0
votes
1 answer
adding values using rowSums and tidyverse
I am having some issues trying to sum a bunch of columns in R. I am analyzing a huge dataset so I am reproducing a sample. of fake data.
Here's how the data looks like (I have 800 columns).
library(data.table)
dataset <- data.table(name = c("A",…

console.log
- 177
- 2
- 16
0
votes
1 answer
Is there a way in R to sumcolumns with different pattern of missing observations?
I have some variables that I wanted to add together but there are missing observations in some of them and when adding together, it will make the whole row with one or more missing as missing. For example, suppose I have the following with the last…
0
votes
3 answers
How to sum df when it contains characters?
I am trying to prep my data and I am stuck with one issue. Lets say I have the following data frame:
df1
Name C1 Val1
A a x1
A a x2
A b x3
A c x4
B d x5
B d x6
...
and I…

antonina
- 109
- 8
0
votes
3 answers
Assign results of rowSums to a new column in R
I have the below dataframe which contains number of products sold in each quarter by a salesman.
Ag Q1 Q2 Q3 Q4
s121 4 3 0 0
S431 0 0 2 1
S246 0 0 0 2
S444 2 2 2 2
I am trying to create a calculated…

Shuvayan Das
- 1,198
- 3
- 20
- 40