I have create a R script that analyse and manipulate 2 different data frame extension, for exemple one task is to extract certain values from data and export it as a .txt file, here is the begining of my script and the data files that i use:
setwd('C:\\Users\\Zack\\Documents\\RScripts\***')
heat_data="***.heat"
time ="***.timestamp"
ts_heat = read.table(heat_data)
ts_heat = ts_heat[-1,]
rownames(ts_heat) <- NULL
ts_time = read.table(time)
back_heat = subset(ts_heat, V3 == 'H')
back_time = ts_time$V1
library(data.table)
datDT[, newcol := fcoalesce(
nafill(fifelse(track == "H", back_time, NA_real_), type = "locf"),
0)]
last_heat = subset(ts_heat, V3 == 'H')
last_time = last_heat$newcol
x = back_time - last_heat
dataest = data.frame(back_time , x)
write_tsv(dataestimation, file="dataestimation.txt")
As u can see i use those 2 files to calculate and extract specific values. My objective is to calculate and extract this values for each file that contain 2 'sub'-files .heat and .timestamp. So can anyone plz tell me how can I run this script on each and every .heat and .timestamp files? I note that I am a windows user.
Thank you for your help
CodePudding user response:
You can search through your directory for files like so.
heat_files = list.files(pattern="*.heat")
time_files = list.files(pattern="*.timestamp")
You could then just loop through them