Jump to content
Simio Forum

Welcome to the Simio Forum

Welcome to the Simio Forum! Experience the full experience of the forum by becoming a Simio Insider! You must be an Insider to post on any forum!

Click_Here_button.png

New Software Release

Our latest release, Simio 11, is here!

Sign in to follow this  
jingalls

R script to Consolidate Write Step Output

Recommended Posts

This script will combine output files from Experiments that use the Write Step. It will average the cells across all selected sheets, and is designed to work with .CSVs that are the same shape.


In R Studio, the code needs to be ran as "source"

 

y = 1
x = 1
fileIterate = 1
readline(prompt="Press Enter To Select Files: ")
fileSave <- choose.files(default = "", caption = "Select files",
                          multi = TRUE, filters = Filters,
                          index = nrow(Filters))
readline(prompt="Press Enter To Select Output Folder: ")
outputFolder <- choose.dir(default = "", caption = "Select folder")
fileName <- readline(prompt="Enter Output File Name: ")

buildFile <-  read.csv(fileSave[fileIterate], header = TRUE, sep = ",")
fileIterate = fileIterate + 1
while(fileIterate <= length(fileSave))
 {
 holderFile <-  read.csv(fileSave[fileIterate], header = TRUE, sep = ",")
 while( y <= ncol(buildFile)){
   while(x <= nrow(buildFile)){
     buildFile[x,y] <- mean(holderFile[x,y],buildFile[x,y])
     x = x + 1;
   } 
   y = y +1;
   x = 1;
 }
 x = 1
 y = 1
 fileIterate = fileIterate + 1
}
fileName <- paste(fileName, ".csv")
outputTheFile <- paste(outputFolder, fileName,sep = "\\")
write.csv(buildFile, file = outputTheFile)

  • Thanks 1

Share this post


Link to post
Share on other sites
Sign in to follow this  

×
×
  • Create New...