I am writing an R code for finding the tensions in my soil profile. I have 100 text files. Cannot go through them manually one by one. The first column of text file is time in days and second is soil tensions; I am getting an error "Error in sprintf("%04.f", i) : object 'i' not found". I cannot understand what is going on. Can someone help.
Here is what the short code looks like:
output[i,1] <- min(tension[,2]) #minimum pressure of surface node
output[i,2] <- tension[which.min(tension[,2]),1] #time of minimum tension
x <- dim(tension) #Number of rows of data in output file
value <- 0 #Starting tension
if (min(tension[,2])<threshold){ #if threshold tension is exceed at some point during the simulations
for (k in 1:x[1]) { #Go through each tension measurement in time order to find when the threshold is exceeded
if(tension[k,2]<threshold) { #If pressure is less than the threshold value
output[i,3] <- tension[k,1] # output time when threshold is crossed
break
}
}
}
else{output[i,3] <- 50*24} #output zero if pressure is not exceeded on that run.
rm("tension") # close current tension file ready to open the enxt one
} else{
output[i,2] <- "=NA()"
output[i,3] <- "=NA()"