You are oh so close.......
You appeared to be moving towards putting into a list, the statistics that you want after each csv is read in. Your syntax for doing that is incorrect, and in my opinion, you do not have to put the values into a list, but rather, put them directly into your summary table. Also, when calculating statistics on a column, you need to use the column form of the statistic (i.e. Col Max() ). Finally, if once you have finished processing of the csv file, you do not have a need for it to continue to hang around, you can simple close it. I added in a line that would do that, but I commented it out. Just remove the // if you want it to take effect.
Names Default To Here( 1 );
// Use a function to open a .CSV file: Given the path to such a file, returns a reference to the resulting table
openMyCSV = Function( {path2File},
{Default Local},
dt = Open(
path2File,
columns(
New Column( "column 1", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "items", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
)
);
// Start your summary table
dt = New Table( "My summary file" );
dt << New Column( "MovAvgMean", Numeric );
dt << New Column( "MovAvgMax", Numeric );
// Put all the .csv files to process into a list
dir = Pick Directory(
"Directory containing your csv files",
"C:\Users\shilpajo\Documents\PV\KT\LIMC\iccMax\DIADEM\JMP\files\"
);
files = Files In Directory( dir );
For( f = N Items( files ), f >= 1, f--,
If( !Ends With( Uppercase( files[f] ), ".CSV" ),
Remove From( files, f )
)
);
// Process each file - Incomplete!
For( f = 1, f <= N Items( files ), f++,
thisTable = openMyCSV( dir || files[f] );
thisTable << New Column( "x",
Numeric,
Continuous,
Formula( 36 + -19.5 * :items + 49.99 * :items * :items * :items )
);
thisTable << New Column( "av", Numeric, Continuous, Formula( Mean( :x[Index( Row() - 9, Row() )] ) ) );
// This will insure that all formula processing is complet before the next statement is run
thisTable << run formulas;
// Add the summary statistics to the summary table
dt << Add Rows( 1 );
dt:MovAvgMean[N Rows( dt )] = Col Mean( thisTable:av );
dt:MovAvgMax[N Rows( dt )] = Col Max( thisTable:av );
// Close( thisTable, nosave );
);
Jim