我有一个 JMP 表,其中包含大约 50 个不同站点每小时测量的数据。在每个站点,数据有时以 ppm 为单位报告,有时以 ppb 为单位报告,有时以两种单位报告,有时根本没有测量值。这是一个相当大的数据集,我想知道 - 如何自动将与每个站相关的列组合成一个单位系统中的单个列。或者我是否必须手动为每个站创建一个新列并输入公式来进行转换? 我只是想在不使用 Excel 的情况下加快此数据准备步骤。
谢谢。有效!现在一切都以 ppm 为单位,我可以继续分析。
这是一个脚本,给出了您显示的结构,会将所有数据转换为 ppm 并删除 ppb 列
这只是起点,如果更多细节改变了计算,它们可以包含在逻辑中
Names Default To Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
If( Trim( Word( -1, Column( dt, i ) << get name, ":" ) ) == "ppm",
ppbCol = Trim( Substr( Column( dt, i ) << get name, 1, Contains( Column( dt, i ) << get name, "ppm" ) - 1 ) || "ppb" );
For( k = 1, k <= N Rows( dt ), k++,
Column( dt, i )[k] = Sum( Column( dt, i )[k], Column( dt, ppbCol )[k]/1000 )
);
)
);
// Get rid of ppb columns
For( i = N Cols( dt ), i >= 1, i--,
If( Trim( Word( -1, Column( dt, i ) << get name, ":" ) ) == "ppb",
dt << delete columns( i )
)
);
毫无疑问,有很多方法可以做到这一点,这是我想到的第一个方法,假设示例中的列格式是一致的。 您可以运行帖子底部的脚本来查看完整的示例,也可以按照脚本中的绿色注释和下面的屏幕截图进行操作:
使用 Stack 将所有站点数据放入一列中:

车站的公式(以“漂亮”格式显示以及双击公式时获得的代码:

单位的公式类似:

每个潜在单位的数据公式:

制表依赖于间隔和站点的序数或名义数据类型:

然后使用表格菜单中的“生成数据表”。
重新创建示例的脚本:
//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;
嗨吉姆,
我发布了一张数据的图片来回答你的问题。请告诉我更改数据的步骤。
谢谢。
数据显示为数字(不带单位 - 或在单独字段中显示单位)还是显示为单位与数字一起出现的字符数据(例如,13ppm)?如果您能提供数据如何显示的示例,那就更容易了。公式应该可以进行您想要的转换,但具体使用什么公式取决于数据的样子。
可以使用一个非常简单的脚本来直接更改它所在列中的值。或者,您可以使用重新编码工具以交互格式执行相同的操作。您如何确定测量单位是什么?是否有一个单独的列表明这一点?