dplyr pipe: how to add a margin row calculating a total (like addmargins function - base)

Viewed 2662

My data:

 data <- data.frame(column1 = c("A","B","C","D"), column2 = c(4, NA, NA, 1))

My pipe:

 library (dplyr)
 data2 <- data %>%
          filter (grepl("A|B|D", column1))

My question: How can I (simply) continue my pipe to add a row containing the total of the column2 (total = 5)?

1 Answers
Related