Reputation: 2533
I am doing some calculations for some files and then I am writing them back. my code here reads the data,does simple calculations, and then write the results and take the same name of the original file.
dir1<- list.files("/data/fgoon", "*.img", full.names = TRUE)
for (files in seq_along(dir1)){
hefile <- readBin(dir1[files], numeric(), size = 4, n = 1300*500, signed = T)
results <- hefile+44.8
outputDir <- "/data/baie"
outputFile <- file.path(outputDir, basename(dir1[files]))
writeBin(as.double(results), outputFile, size = 4)
}
The original file name is for example
dert_E_lwe_20030102_yout.img
What I need is to return the same name (as done in the code) but change lwe
to sh
for all files:
dert_E_sh_20030102_yout.img
all parts of the name are the same for all files except the date. Any help is appreciated!
Upvotes: 0
Views: 33
Reputation: 2220
You can use something like this (it's an idea):
str_replace_all(basename(dir1[files]),"lwe","sh")
Upvotes: 1