How to transform NA values in to 0 in a raster layer

Hi @GabrielYan , if the data is dtb,
Remmember put a reproducible example for better understand all the community.

Try with this:

library(dplyr)
dtb<- dtb %>% replace(is.na(.), 0)