library(dplyr)
set.seed(2)
tol <- .1
(D <- data.frame(from=runif(40,-1,1),
to=runif(40,-1,1)))
(D2 <- D |> mutate(across(c(from,to),
\(x){
within_tol <- abs(x)<=tol
ifelse(within_tol,
0,x)
})))
#to snoop on differences
waldo::compare(D,D2)
(D3 <- D2 |> mutate(weight=from+to))