-1

I have a data table, see eg below:

A B C D 
1 a 2 4
2 b 3 5
3 c 4 6

with A,B,C,D as columns, I want to add a new column with sums across rows for column A,C and D. thus, new column should be

A B C D  SUM
1 a 2 4  7
2 b 3 5  9
3 c 4 6  13

Can someone please suggest.

Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
jalaj pathak
  • 55
  • 1
  • 8

1 Answers1

0

You can use the following code

library(tidyverse)

df <- read.table(header = TRUE, text ="A B C D

    1 a 2 4

    2 b 3 5

    3 c 4 6")

df %>% mutate(SUM = rowSums(select(df, c(A, C, D))))
Bappa Das
  • 5,817
  • 3
  • 18
  • 40