各位,
我有包含 ID、上次檢查數據和上次檢查決策列的數據表。 我想將最後一次檢查數據列與最後一次檢查決策結合起來,以便將一列(堆疊)用於關聯分析。 例如,我的數據結構的一個集群如下所示:
ID 上次檢查決策 上次檢查數據
101 產品規格缺陷
101 CGMP 偏差
101 21 美國聯邦法規 211.113
101 奧鋼聯 LIQ_US
我想將上次檢查決策(在本例中為 VAI)移至上次檢查數據列下,並創建具有相同 ID(在本例中為 101)的新行。 因此我需要我的堆疊數據如下:
ID 最後檢查數據
101 產品規格缺陷
101 CGMP 偏差
101 21 美國聯邦法規 211.113
第101章
101 奧鋼聯
此外,這些ID中的一些在一個或多個上次檢查數據中是重複的但具有不同的值。 例如,實驗室缺陷可能是同一 ID 的另一個問題,因此當這些值中的任何一個與前一個值不同時,我都會創建另一個行簇。
ID 上次檢查決策 上次檢查數據
101 實驗室缺陷
101 CGMP 偏差
101 21 美國聯邦法規 211.113
101 奧鋼聯 LIQ_US
非常感謝您提前提供的幫助。
最好的,
蓋斯
我不確定我是否理解正確,但這是另一種選擇。 如果這是您想要的,您還需要看看它的擴展能力如何。
NamesDefaultToHere(1);
// Example table . . .
dt = New Table( "Inspection",
Add Rows( 10 ),
New Column( "ID",
Character,
"Nominal",
Set Values(
{"101", "101", "101", "101", "102", "102", "102", "101", "101", "101"}
)
),
New Column( "Last Inspection Decision",
Character,
"Nominal",
Set Values( {"", "", "", "VAI", "", "", "Code 1", "", "", "Code 2"} )
),
New Column( "Last Inspection Data",
Character,
"Nominal",
Set Values(
{"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113",
"LIQ_US", "PRODUCT SPECIFICATIONS DEFECT", "21 CFR 211.113", "LIQ_US",
"PRODUCT SPECIFICATIONS DEFECT", "CGMP Deviations", "21 CFR 211.113"}
)
)
);
// Copy the table
dt2 = Eval(dt << getScript);
dt2 << setName(dt << getName ||" Stacked");
// Get the values from the two columns of interest into lists
ids = Column(dt2, "ID") << getValues;
vals = Column(dt2, "Last Inspection Data") << getValues;
// Find out where we need to insert new values, get the required values, and insert them into the right positions
insertAfter = dt2 << getRowsWhere(!IsMissing(:Last Inspection Decision));
for(r=1, r<= NItems(insertAfter), r++,
InsertInto(ids, Column(dt2, "ID")[insertAfter[r]], insertAfter[r] + r);
InsertInto(vals, Column(dt2, "Last Inspection Decision")[insertAfter[r]], insertAfter[r] + r);
);
// Add rows to teh copy of the table, insert the column values, and delete the column we don't need
dt2 << addRows(NRows(insertAfter));
Column(dt2, "ID") << setValues(ids);
Column(dt2, "Last Inspection Data") << setValues(vals);
dt2 << deleteColumns(:Last Inspection Decision);
你好,
它不起作用,因為我有超過 100,000 行。 我嘗試將數據分成三部分,每部分幾乎有 35,000 行,但它不起作用。 有什麼建議嗎?
最好的,
蓋斯
這不是最強大的解決方案,但請嘗試一下:
dt = current data table ();
for each row( if(!is missing (:Last Inspection Decision),
dt << add rows(1, row()),
is missing (:Last Inspection Data), :Last Inspection Data[row()] = :Last Inspection Decision[row()-1])
);