我有一個 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)?如果您能提供數據如何顯示的範例,那就更容易了。公式應該可以進行您想要的轉換,但具體使用什麼公式取決於資料的樣子。
可以使用一個非常簡單的腳本來直接更改它所在列中的值。或者,您可以使用重新編碼工具以互動格式執行相同的操作。您如何確定測量單位是什麼?是否有一個單獨的列表明這一點?