透過統計表中的批次來建立資料表大家好,JMP 社區
我有一個僅部分填寫了批號的資料集。
我的目標是建立一個包含一行 pr 的資料集。批。
我可以透過比較第一批和最後一批號碼來計算需要多少行。
如例所示,我需要一個包含 30 行的資料集作為第一個批號。是 7,最後一個是 37。
在批次名稱中,應忽略前 3 位數字和後 2 位數字。
在我看來,這應該是很簡單的,但我卻陷入了困境…
我將非常感激能夠擺脫困境!
謝謝
基督教
自動化和腳本資料混合與清理回覆:透過統計表中的批次來建立資料表嗯,我不明白您的疑問?您有多個包含相同資訊的行(前 3 行,以及第 4 行和第 5 行),您缺少第 21-23 行、第 25-26 行、第 29 行?前 6 位數字也相同。
你到底想做什麼?您隨時可以右鍵單擊該列並使用重新編碼。
回覆:透過統計表中的批次來建立資料表像這樣嗎?它會建立一個新表,每個批次只有一行,而不是多行,並填寫缺少的批次。
Names Default To Here( 1 );
Batch_vals = Associative Array( :Batch ) << Get Keys;
prefix = Left( :Batch[1], 3 );
suffix = Right( :Batch[1], 2 );
rootlength = Length( Batch_vals[1] ) - Length( prefix ) - Length( suffix );
Batch_nums = Transform Each( {v, i}, Batch_vals, Num( Substitute( v, {prefix, suffix}, "" ) ) );
Min_batch = Min( Batch_nums );
Max_batch = Max( Batch_nums );
Batches = Min_batch :: Max_batch;
dt = New Table( "Batches", New Column( "Batch Number", numeric, continuous, Set Values( Batches ) ) );
Eval(
Eval Expr(
dt << New Column( "Batch", character, Formula( Expr( prefix ) || Right( Char( :Batch Number ), rootlength, "0" ) || Expr( suffix ) ) )
)
);
dt:Batch << Delete Formula;回覆:透過統計表中的批次來建立資料表這不會創建批號,而只是數字。
Names Default To Here(1);
dt = Data Table("Format");
Summarize(dt, uniq = By(:Batch));
first_val = Num(Substr(uniq[1], 4, Length(uniq[1]) - 5));
last_val = Num(Substr(uniq[N Items(uniq)], 4, Length(uniq[1]) - 5));
dt = New Table("Res",
New Column("R", Numeric, Ordinal, Values(first_val::last_val))
);
您可以透過將該項目清單轉換為字串並從中建立表格來新增批次(與前面的 first_val 和 last_val 相同)
batches = Transform Each({item}, As List((first_val::last_val)`),
"245" || Right("00000" || Char(item), 5) || "00"
);
dt = New Table("Res2",
New Column("R", Character, Ordinal, Values(batches))
);回覆:透過統計表中的批次來建立資料表謝謝 Jarmo!這太完美了。
在撰寫這篇文章時,我正在吹噓 JMP 社群有多麼令人難以置信,而我並沒有失望!
歡呼吧,克里斯蒂安
回覆:透過統計表中的批次來建立資料表感謝@mmarchandFSLR的回覆!
你的腳本運行完美!
您的解決方案包含一些對我來說很新的提示/腳本,例如,關聯數組、Transform Each、Eval、Eval Expr。
我期待深入了解您的解決方案如何發揮作用!
在撰寫這篇文章時,我吹噓了 JMP 社群有多麼不可思議,我並沒有失望!
歡呼,克里斯蒂安
回覆:透過統計表中的批次來建立資料表簡單解釋一下其中一些功能和一個重要的改變:
Names Default To Here( 1 );
//An associative array is a dictionary or hash map that links keys to values. Each key must be unique.
//Using a single column as the argument for the array gives us the unique values of the column with each value set to 1
//The <<GET keys="" message="" then="" yields="" the="" only=""></GET>
回覆:透過統計表中的批次來建立資料表您可以透過依序增加批號來建立行。