我已经找到了一个可以工作的脚本,但不知怎的,它在不处理结果的情况下继续运行,运行和运行。
那是脚本
#working directory#
setwd("C:\\Users")
#data-files#
data = list.files(pattern="*.csv", full.names= TRUE)
Y = length(data)
#Output#
output= data.frame(V1=NA, V2=NA, V3=NA, V4=NA, V5=NA, V6=NA, V7=NA, V8=NA, V9=NA, V10=NA)
for (i in 1:Y) {
A <- read.csv(file=data[i], header=TRUE, sep=";")
Duration = as.character (A[8,1])
Duration = as.numeric(strsplit(Duration," ") [[1]][4])
Timesteps = as.character((A[(13+Duration),1]))
Timesteps = as.numeric(strsplit(Timesteps," ") [[1]][2])
V1 = as.numeric(which(A==63569))
V1 = as.numeric(max(as.character(A[(V1+1):(V1+Timesteps),1])))
V2 = as.numeric(which(A==41510))
V2 = as.numeric(max(as.character(A[(V2+1):(V2+Timesteps),1])))
V3 = as.numeric(which(A==12885))
V3 = as.numeric(max(as.character(A[(V3+1):(V3+Timesteps),1])))
V4 = as.numeric(which(A==43954))
V4 = as.numeric(max(as.character(A[(V4+1):(V4+Timesteps),1])))
V5 = as.numeric(which(A==44422))
V5 = as.numeric(max(as.character(A[(V5+1):(V5+Timesteps),1])))
V6 = as.numeric(which(A==42137))
V6 = as.numeric(max(as.character(A[(V6+1):(V6+Timesteps),1])))
V7 = as.numeric(which(A==28667))
V7 = as.numeric(max(as.character(A[(V7+1):(V7+Timesteps),1])))
V8 = as.numeric(which(A==63570))
V8 = as.numeric(max(as.character(A[(V8+1):(V8+Timesteps),1])))
V9 = as.numeric(which(A==44525))
V9 = as.numeric(max(as.character(A[(V9+1):(V9+Timesteps),1])))
V10 = as.numeric(which(A==43192))
V10 = as.numeric(max(as.character(A[(V10+1):(V10+Timesteps),1])))
#OUTPUT-FILES#
output [i,1] <- V1
output [i,2] <- V2
output [i,3] <- V3
output [i,4] <- V4
output [i,5] <- V5
output [i,6] <- V6
output [i,7] <- V7
output [i,8] <- V8
output [i,9] <- V9
output [i,10] <- V10
}
#result#
setwd("C:\\Users")
write.table(output,file= "XY.csv", sep= ";", dec=".", row.names=FALSE)
也许我设置它的方式是错综复杂,或者我错过了一个相当简单的部分。我现在无法帮助自己。
提示非常感谢!
干杯, 奥利