setwd("Put the path of your working folder here") myfile1 <- list.files() myfile2 <- lapply(myfile1, read.csv) j <- 1 for (i in myfile2) { i$Distance <- ifelse(abs(i$Distance)>0.3, i$Distance, 0) write.csv(i, paste0(myfile1[j])) j <- j+1 }