How do I replace NA
values by -
in my code below:
library(dplyr)
output<-structure(list(date = structure(c(18808, 18810), class = "Date"),
ABC = c(4, 1), CDE = c(1, NA), FGH = c(6, NA)), row.names = c(NA,
-2L), class = "data.frame")
output<-output %>% mutate(SUM = rowSums(across(2:last_col()), na.rm = TRUE))
> output
date ABC CDE FGH SUM
1 2021-06-30 4 1 6 11
2 2021-07-02 1 NA NA 1