No doubt there are many ways to do this, here is the first that came to mind assuming the column format in your example is consistent. You can either run the script at the bottom of the post to see a full example or follow along with the green comments in the script and the screenshots below:
Bring all station data into a single column using Stack:
Formula for Station (shown both in the 'pretty' format and the code you get when double clicking on the formula:
Formula for Unit is similar:
Formula for Data accounts for each potential unit:
Tabulate relies on the ordinal or nominal data type for Intervals and Station:
Then use Make Into Data table from the tabulate menu.
Script to recreate an example:
//To see a full example you can copy this this into a new script window and press Run, or just following along
//with the green comments
Names default to here(1);
//Recreate part of your sample data table, you could skip this part and open your original data instead
//Note that the times are ordinal or nominal data types, this will be imporant in the tabulate platform later
dt = New Table( "Raw Data",
Add Rows( 2 ),
New Column( "IntervalStart", Numeric, "Ordinal", Format( "m/d/y h:m", 19 ), Input Format( "m/d/y" ),
Set Values( [3503606400, 3503610000] ),
),
New Column( "IntervalEnd", Numeric, "Ordinal", Format( "m/d/y h:m", 19 ), Input Format( "m/d/y h:m" ),
Set Values( [3503609940, 3503613540] )
),
New Column( "StationName: Anzac-Unit:ppb", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [1, 2] ) ),
New Column( "StationName: Anzac-Unit:ppm", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., .] ) ),
New Column( "StationName: Ardrossan-Unit: ppb", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., .] ) ),
New Column( "StationName: Ardrossan-Unit: ppm", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [11, 12] ) )
);
//Get a reference to your current data table
dt = Current data table();
//Stack all of the columns - use Tables > Stack and include all of the columns except the first two which are times
dtStacked = dt << Stack(
columns(
(dt << Get Column Names())[3::n col(dt)]
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
//Now add three new columns to find the station and units, and calculate the concentration based on the units
//you should be able to copy and paste the part inside the 'Formula' function below into the formulas of your new columns
dtStacked << New Column("Station", Character, "Nominal", Formula(Words(:Label, "-")[1]));
dtStacked << New Column("Unit", Character, "Nominal", Formula(Words(:Label, "-")[2]), Set Display Width(65));
dtStacked << New Column("Data (ppm)", Numeric, "Continuous", Format("Best", 12), Formula(If(Contains(:Unit, "ppm"), :Data, Contains(:Unit, "ppb"), :Data / 1000)));
//Put back in standard format using the tabulate platform. Drag times and the station into
//columns on the left and add the mean and N as data fields. Note that in the resulting table anything
//with a N(Data) greater than 1 might have a problem!
(dtStacked << Tabulate(
Show Control Panel( 0 ),
Add Table(
Column Table( Analysis Columns( :Data ), Statistics( Mean, N ) ),
Row Table( Grouping Columns( :IntervalStart, :IntervalEnd, :Station ) )
)
)) << Make Into Data Table;