sum cells of certain columns for each row

前端 未结 3 1342
既然无缘
既然无缘 2020-12-10 02:03

I would like to calculate sums for certain columns and then apply this summation for every row. Unfortunately, I can only get to the first step. How do I now make it happen

相关标签:
3条回答
  • 2020-12-10 02:23

    If you don't have NA you can apply this

    suma.zscore = (zscore$a + zscore$c + zscore$t + zscore$y)
    
    0 讨论(0)
  • 2020-12-10 02:25

    The summation of all individual rows can also be done using the row-wise operations of dplyr (with col1, col2, col3 defining three selected columns for which the row-wise sum is calculated):

    library(tidyverse)
    
    df <- df %>% 
        rowwise() %>% 
        mutate(rowsum = sum(c(col1, col2,col3)))
    
    0 讨论(0)
  • 2020-12-10 02:38

    You could do something like this:

    summed <- rowSums(zscore[, c(1, 2, 3, 5)])
    
    0 讨论(0)
提交回复
热议问题