I have a dataframe, and I want to assign NA to non-positive values of specific columns.
I'll try to realize a minimal reproducible example with the mtcars dataframe where I'll try to change with NA the values of the two columns cyl and disp that are <= 5.
library(dplyr)
view(mtcars)
Nomi <- c("cyl", "disp")
for(i in Nomi) {
mtcars$i[mtcars$i <= 5] <- NA
}
Nomi is the vector with the names of mtcars columns where I want to change values with NA.
I don't fully understand the error message I get, I'd like to find a solution that can make the changes in NA.