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

total of all rows in new column pandas

question:- get the total of all one two columns bar baz foo one two one two one two name A 0.895717 0.805244 1.206412 2.565646 …
ZAVERI SIR
  • 317
  • 4
  • 14
-1
votes
1 answer

Sum rows based on names and create new df

I want a help for a personal project! i have a df (Name x Date) looking like this Name1 Name2 Name3 Name3 Name 4 Name5 Name6 Name 3 Date 1 x1 x2 x3 x4 x5 x6 x7 x8 Date 2 y1 y2 y3 y4 y5 y6 y7 …
-1
votes
1 answer

Error in ncol(xj) : object 'xj' not found using rowSums

I'm using R and rowSums function for a data frame as discussed in this post: Sum over spatialGridDataFrame: rowSums or colSums. Now suing rowSums as follows: FLintMod[[2+nsim]] <- rowSums(FLintMod@data[, 2:(1+nsim)], na.rm=TRUE) Now I'm facing new…
Mohammad
  • 67
  • 1
  • 9
-1
votes
1 answer

lapply, rowSums and passign arguments

Consider this code lapply(lst,rowSums) lst is a list of five data frames. Each data frame has, for example, four columns and ten rows. I want to add the values of the columns in each row, however, I do not want to include the value of column one in…
MOON
  • 2,516
  • 4
  • 31
  • 49
-1
votes
1 answer

How can I use rowSums() after multiple imputation with MICE package in R

I have a short question: I imputed item data using multiple imputation with the MICE package. After imputation, I would like to sum items to a total score. However, my data is now in a mids object, and I can't figure out how to do this simple…
L. Bakker
  • 147
  • 1
  • 13
-1
votes
4 answers

Ragged rowSums in R

I am trying to do a rowSum for the actuals columns. However, I would like to include the values up to the UpTo date for certain observations. Here is the data frame: dat <- structure(list(Company = c("ABC", "DEF", "XYZ"), UpTo = c(NA, "Q2", "Q3"),…
J Kang
  • 1
  • 5
-1
votes
1 answer

Select columns using a vector

I am trying to create a new data frame with 2 columns: var1 and var2, each one of them is the row sum of specific columns in data frame sampData. library(dplyr) sampData <- rnorm(260) %>% matrix(ncol = 26) %>% data.frame() %>% …
user4797853
  • 71
  • 1
  • 9
-1
votes
1 answer

Summing Rows in Matrices created by lapply

I'm brand new to R and I'm trying to figure out how to sum the rows from the following output. u <- c(1,2,3) x <- lapply(u, replicate, rbinom(10,1,.5)) When I do this x is equal to [[1]] [,1] [1,] 0 [2,] 0 [3,] 1 [4,] 1 [5,]…
Jarom
  • 1,067
  • 1
  • 14
  • 36
-2
votes
3 answers

How to get the sum of rows using a vector and the make the result in a column

I have a dataframe and i want to calculate the sum of variables present in a vector in every row and make the sum in other variable after i want the name of new variable created to be from the name of the variable in vector for example data Name …
Reda
  • 449
  • 1
  • 4
  • 17
-2
votes
3 answers

Assigning values to a column in the based on values of another column in the same dataframe in R

I have a dataframe with 3 columns and I want to assign values to a fourth column of this dataframe if the sum of a condition is met in another row. In this example I want to assign 1 to df[,4], if df[,3]>=2 for each row. An example of what I want as…
Debutant
  • 355
  • 5
  • 17
-2
votes
1 answer

Why does rowSums work for some variables and doesn't vork for others?

I am using the following lines of code for creating a new variable from other variables: FER_TMS_nopractice_recoded_replaced %>% select(FACE.RT, SCRAM1.RT_total, SCRAM2.RT_total, SCRAM3.RT_total, SCRAM4.RT_total,…
-2
votes
1 answer

rowSum problems in dplyr - 'x' must be numeric

I come across problems when trying to make rowSums in dplyr. After grouping the data via data <- data %>% group_by(location, category) %>% summarise(amount = sum(amount)) %>% spread(key = "category", value = "amount", fill = 0) The output…
Christopher
  • 2,120
  • 7
  • 31
  • 58
1 2 3
13
14