I have a table that I'm trying to add multiple columns together in a new column. I've tried simple rowSums in different forms and it will create the new column but the values don't add.
col1 | col2 | col3 | col4 |
---|---|---|---|
10 | 25 | 15 | 25 |
99 | 42 | 20 | 35 |
I've tried
df$col5 <- rowSums(df[c("col1","col2","col3",col4")])
and
df <- df %>% mutate(col5 = rowSums(select(.,"col1","col2","col3",col4")
and
df <- df %>% mutate(col5 = sum(c_across(col1:col4)
But each time it returns
col1 | col2 | col3 | col4 | col5 |
---|---|---|---|---|
10 | 25 | 15 | 25 | NA |
99 | 42 | 20 | 35 | NA |