我已经在这个脚本上工作了很长时间,但我仍然遇到同样的错误。文件选择窗口会弹出,但是当我选择要处理错误的文件时说明:
“文件错误(文件,”rt“):无法打开连接”
出现。有什么建议或想法吗?
library(reshape)
library(tcltk2)
mergedPLT <- tk_choose.files(caption = "Select all PLT files", multi = TRUE)
mergedPLT = dir(pattern="*.plt");
fullData = NULL
for (i in 1:length(mergedPLT))
{
currFileName = mergedPLT[i]
allData <- read.csv(currFileName, header=FALSE, sep=" ")
# Verify variable locations later
accelerate <- as.numeric(allData$V1) # V1
latAcc <- as.numeric(allData$V2)
accPedal <- as.numeric(allData$V3)
BrkPedFor <- as.numeric(allData$V4)
Gear <- as.numeric(allData$V5)
Heading <- as.numeric(allData$V6)
HeadingError <- as.numeric(allData$V7)
HeadDis <- as.numeric(allData$V8)
HeadTime <- as.numeric(allData$V9)
LaneNum <- as.numeric(allData$V10)
LaneOff <- as.numeric(allData$V11)
RoadOff <- as.numeric(allData$V12)
StrWPos <- as.numeric(allData$V13)
TailDis <- as.numeric(allData$V14)
TailTime <- as.numeric(allData$V15)
Velocity <- as.numeric(allData$V16)
LatVelocity <- as.numeric(allData$V17)
VerVelocity <- as.numeric(allData$V18)
XPos <- as.numeric(allData$V19)
YPos <- as.numeric(allData$V20)
ZPos <- as.numeric(allData$V21)
Roll <- as.numeric(allData$V22)
Pitch <- as.numeric(allData$V23)
Yaw <- as.numeric(allData$V24)
RPM <- as.numeric(allData$V25)
SlipFrtR <- as.numeric(allData$V26)
SlipFrtL <- as.numeric(allData$V27)
SlipRearR <- as.numeric(allData$V28)
SlipRearL <- as.numeric(allData$V29)
mergedData <- data.frame(accelerate,latAcc,accPedal,BrkPedFor,Gear,Heading,HeadingError,HeadDis,HeadTime,LaneNum,LaneOff,RoadOff,StrWPos,TailDis,TailTime,Velocity,LatVelocity,VerVelocity,XPos,YPos,ZPos,Roll,Pitch,Yaw,RPM,SlipFrtR,SlipFrtL,SlipRearR,SlipRearL)
fullData = rbind(mergedData) # Use cbind to select certain areas
}
write.csv(fullData, file = "SimData.csv")
此脚本只是从.plt格式的文件中获取值,并将它们重写为.csv文件。