Jump to content

R script to Consolidate Write Step Output


jingalls
 Share

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
Link to comment
Share on other sites

×
×
  • Create New...