我創建了一個 R 腳本來分析和操作 2 個不同的資料框擴展名,例如,一項任務是從資料中提取某些值并將其匯出為 .txt 檔案,這是我的腳本和我使用的資料檔案的開頭:
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")
如您所見,我使用這 2 個檔案來計算和提取特定值。我的目標是為包含 2 個“子”檔案 .heat 和 .timestamp 的每個檔案計算并提取此值。那么任何人都可以告訴我如何在每個 .heat 和 .timestamp 檔案上運行這個腳本?我注意到我是 Windows 用戶。
感謝您的幫助
uj5u.com熱心網友回復:
你可以在你的目錄中搜索這樣的檔案。
heat_files = list.files(pattern="*.heat")
time_files = list.files(pattern="*.timestamp")
然后你可以回圈遍歷它們
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/341301.html
標籤:r
上一篇:如何計算帶有值的列
