first, I invite you to learn how to provide example data in a forum friendly way reprex
Here is your data, as it would have been output via dput() , this would have been much easier for you no doubt, than it has been for me to get it into this form...
df1 <- structure(list(id = 1:10, A = c(
2L, -1L, 3L, -3L, 4L, NA, 3L,
-1L, 4L, 1L
), B = c(3L, -7L, 3L, 9L, NA, 3L, 5L, 9L, -3L, -3L), C = c(1L, -1L, 2L, 1L, NA, 0L, NA, 0L, 2L, -7L), D = c(
1L,
2L, -3L, 4L, NA, 1L, 2L, -3L, 4L, 2L
), E = c(
2L, NA, -3L, 2L,
NA, 2L, 3L, 2L, -7L, NA
)), row.names = c(NA, -10L), class = c(
"tbl_df",
"tbl", "data.frame"
))
now a possible solution:
library(tidyverse)
revalue_func <- function(x) {
case_when(
x %in% c(-1, -3) ~ NA_integer_,
x == -7 ~ 0L,
TRUE ~ as.integer(x)
)
}
mutate(df1,
across(A:E,
revalue_func))