I am trying to replace NA values with 0 for a specific set of columns in my tibble. All the columns start with the same prefix. So, I want to know if there is a concise way to make use of the starts_with() function from the dplyr package that would allow me to do this.
I have tried replace_na() function from the tidyr package to no avail. Below is the code.
library(tidyverse)
tibble1 <- tibble(
id = c(10, 20, 30),
col_a = c(1, NA, 4),
col_b = c(NA, 99, 100),
col_c = c("d", "e", NA)
)
replace_na(tbl1, list(starts_with("num_") = 0)))