使用轉置將資料子集從一個表移動到第二個表的列我很抱歉再次發布此內容。我已經在這裡發布了我的工作流程的點點滴滴,被掩蓋了,以尋求幫助,但我仍然在掙扎。我很難檢查回复,因為我在 StackOverflow 上有過被無緣無故大喊大叫的糟糕經歷。我確信傷疤會隨著時間的推移而癒合。不管怎樣,我就在身邊,我最終會得到你的回應。
進入技術要點:
我正在嘗試將一些示例的運行日期(每個示例應該在 3 個不同的場合運行,假設在專案的實驗室部分一切順利,而我不在場)複製到清單文件的三個單獨的列中根據我收集的信息,它跟踪我們項目的持續元數據,以便每一列都是數據收集的一個實例。有多個捐贈者,每個捐贈者都有一個捐贈者ID,並且數據中存在一些冗餘,例如儀器上針對“相同數據點”的多個收集通道(取決於您如何看待它),儘管我認為應該是這樣。
這是我一直在嘗試解決的偽代碼,到目前為止還很粗糙。我不知道為什麼。我不是經驗豐富的電腦科學家、開發人員或軟體工程師。任何幫助表示讚賞。
DataTypes:
(associative array) DonorID{
(key) Month1: (value) date1 (empty at start)
(key) Month2: (value) date2 (empty at start)
(key) Month3: (value) date3 (empty at start)
}
find unique donor IDs in data
for each donor ID{
get (i.e. subset) data keyed on donor ID;
for Month in 1, 2, 3 (strings){
if no date in donorID associative array{
add date from data;
}else if date already{
is the date in the data table cell the same as in the associative array entry?
if yes, do nothing (indicates different target channel)
if no, ping user
Multiple run dates for same data point is a problem.
}
}
}
Copy from data to manifest:
loop over DonorID associative array:
for each donorID:
in Month 1, 2, or 3:
add date1 2 or 3 to "Actual Month [1, 2, or 3] Stability Test Date" in manifest
donorID is still row identifier
date (1, 2, or 3) is now column identifier
資料混合與清理回复:使用轉置將數據子集從一個表移動到第二個表的列現在我正在嘗試將數據/日期分配給具有正確 ID 的行中的清單文件:
... );
//write(LBCM_array);
dt_manifest << Get Rows Where(dt_manifest:ID Number for Updating Table == ID)[:Actual Data 1 Date] = data_array["data1"];
//repeat for data 2 & 3
);
真的,作為一個初學者,我仍然不知道如何從 JSL 開始,所以我得到了錯誤
["data1" => {}, "data2" => {}, "data3" => {}]
attempting to assign to an object that is not an L-value in access or evaluation of 'Assign' , dt_manifest << Get Rows Where(
dt_manifest:ID Number for Updating Table == ID
)[:Actual Data 1 Date] = /*###*/data_array["data1"] /*###*/我不知道這是什麼意思。
謝謝,
麥克風
回复:使用轉置將數據子集從一個表移動到第二個表的列以下對我有用...
Names Default To Here( 1 );
dt_data = Open("...");
Summarize( dt_data, IDs = by(dt_data:ID)); //this finds all the unique donor IDs in the data file, which we will need
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest data file.
For(i = 1, i <= N Items(IDs), i++,
ID = num(IDs[i]); //the type conversion here is important, or else a key-value call in the associative array below doesn't work
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} ); //it appears in the print statements we get 3 copies, indicating this loop works
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
data_array[data] = dt_data:Run date[dt_data << Get rows Where(:ID == ID & :Timepoint == data)]
);
);除了現在我在 data_array 中有每個數據(日期時間點)條目的多個副本。 我想知道如何清理乾淨,只為 data_array 中的每個日期/數據製作一份副本?
我一直在嘗試使用 if 語句,使用 As Date() 語句來比較和格式化日期以進行比較和輸入,以確保我們只獲得一個唯一值。 但到目前為止,這給我帶來了問題(即數組變成錯誤或再次為空)。
不過,我對到目前為止的進展感到非常滿意。
@txnelson : 抱歉,我喜歡你的方法並感謝你的幫助,但你會注意到我能夠在沒有你的索引“k”技術的情況下隨意擺弄它
。 (我想知道當有多個相同值的日期時你的方法如何公平,這就是我的情況?)
@brady_brady :請注意,我在適當的列調用之前實施了數據表標識符。 謝謝你教我這個基本概念;我對它非常好奇,谷歌搜索到現在都沒有結果。
麥克風
回复:使用轉置將數據子集從一個表移動到第二個表的列大家好。 實際上,這一次我正在取得進步,而不是在不知道該往哪個方向前進的情況下被困在某件事上。
目前我的一個鍵/值對不適合,所以我從我的一個數組調用中得到了不正確的結果。 我正在嘗試對此進行調試,以便我可以將數據表正確地子集/過濾到我想要傳輸到關聯數組的內容。
非常感謝您的幫助。
麥克風回复:使用轉置將數據子集從一個表移動到第二個表的列謝謝你,布雷迪。 這一切對我來說都很有意義。
看起來其中一些實際上是我代碼中的問題。 我已經解決了他們並且正在前進。 我有新問題,一旦我弄明白了就會發布。
麥克風
回复:使用轉置將數據子集從一個表移動到第二個表的列嗨,吉姆。 感謝您的答复。 你介意用人類英語解釋你的代碼是如何工作的嗎? 我的解釋是:所有ID唯一的行都放在theRows中。 然後,索引k被實例化。它在將運行日期添加到數據數組的循環內遞增。在這個循環中,現在,而不是我以前擁有的,theRows 中的每個唯一值都用作索引來訪問 :Run date,並將結果填充到數據數組中。
如果我研究得更久一點,這對我來說就有意義了。 乍一看不是太清楚。 不確定。 但是您確實在帖子末尾用一行結論進行了解釋。
在我用我的代碼中的真實變量替換所有被擦除的變量後,我得到錯誤:
invalid subscript (must be number or list of numbers) in access or evaluation of 'theRows[k]' , theRows[/*###*/k]
我不知道為什麼。
我仍然很困惑,我將繼續研究這段代碼。 很奇怪,我在大學裡上了相當多的編碼課程,但我沒有維護我的知識庫,所以我想它可能會隨著時間的推移而消失。
謝謝您的幫助!
邁克爾
PS:關於為什麼使用關聯數組:認為這將是一種有效的數據傳輸方式,作為 JMP 初學者,具有更多 Java/Python 方面的經驗。 您會推薦直接操作表格嗎? 不過,到目前為止,我一直沿著這條路走,我想知道以這種方式完成手頭的任務是否會很有趣。
回复:使用轉置將數據子集從一個表移動到第二個表的列你好,
你寫:
我現在的問題是這一行:
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
我看到了幾個潛在的問題......一定要調查這些:
1):運行日期,如所寫,指的是解釋這行代碼時當前數據表中的列。 從報錯信息來看,在解釋這行代碼時,當前數據表中並沒有名為“Run Date”的列。 我看到你開了兩張桌子;始終確保目標表確實是當前表,如果由 JMP 決定使用哪個表。 您可以使用當前數據表命令強制任何您希望成為當前表的表:
dt1 = open("firstfile");
dt2 = open("secondfile");
Current Data Table (dt1); // sets first table current
Current Data Table (dt2); //sets second table current
不過,您不必讓 JMP 來決定。 您可以使用表:列格式,如:
dt1:Run Date
2) 解決表貨幣問題後,您需要使用<< 獲取行,其中 ( )消息,發送到適當的數據表,返回滿足某些條件的行。 通常這些被用作索引,就像你的情況一樣。 假設您要使用 dt1,則代碼將顯示為:
data_array[data] = dt1:Run Date[dt1 << Get rows Where(:ID == ID & :Timepoint == data)];
這條線做了 3 個工作:
1) 獲取 dt1 中滿足某些條件的行,將它們返回到向量中。 請注意,因為<< 獲取行 where() message發送到dt1,可以理解::ID和:Timepoint也在dt1中。
2) 使用上面步驟 1 中返回的向量作為 dt1:Run Date 的索引,它是 dt1 中的 Run Date 列。 因為我們已經使用 dt1:Run Date 將運行日期顯式限定為 dt1 表,所以 dt1 是否恰好是當前表並不重要。 完成第 2 步後,會從“運行日期”列返回一個值向量——正是我們想要的值。
3) 將上面步驟 2 中返回的運行日期值的向量分配為特定鍵的值,數據,在關聯數組中,數據數組.
乾杯,
布雷迪
回复:使用轉置將數據子集從一個表移動到第二個表的列麥克風,
我對為什麼要使用關聯數組仍然有些迷惑,但無論如何,我相信下面的代碼將移入數組,每個 ID 的 3 個測量行的日期值。我編造了一些數據,希望它們與您的數據佈局相似。我只是根據您的陳述和代碼使用情況進行猜測。

這是腳本。上面的數據表是在腳本的開頭生成的,所以你的代碼的內容,經過我的修改,在數據表生成下面。
Names Default To Here( 1 );
dt_data = New Table( "Example",
Add Rows( 6 ),
New Column( "ID", Character, "Nominal", Set Values( {"A", "A", "A", "B", "B", "B"} ) ),
New Column( "Run Date",
Numeric,
"Continuous",
Format( "m/d/y", 12 ),
Input Format( "m/d/y" ),
Set Values( [3692304000, 3694982400, 3697401600, 3700080000, 3702672000, 3705350400] )
),
New Column( "TimePoint", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [., ., ., ., ., .] ) )
);
//dt_manifest = Open( "[filepath, no issues here]" );
Summarize( dt_data, IDs = by( :ID ) ); //this finds all the unique IDs in the data file, which we will need //[no issues here]
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest file.
For( i = 1, i <= N Items( IDs ), i++,
ID = IDs[i];
theRows = dt_data << get rows where( :ID == ID );
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} );
k=0;
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
k++;
show( ID ); //just a check; works
data_array[data] = :Run date[theRows[k]];
//...continue with further code to transfer from LBCM_array to manifest
);
show(data_array);
);
代碼的結果列在日誌中
ID = "A";
ID = "A";
ID = "A";
data_array = ["data1" => 3692304000, "data2" => 3694982400, "data3" => 3697401600];
ID = "B";
ID = "B";
ID = "B";
data_array = ["data1" => 3700080000, "data2" => 3702672000, "data3" => 3705350400];
data_array 中的數字是運行日期的數值。
回复:使用轉置將數據子集從一個表移動到第二個表的列大家好。 到目前為止,這是我的代碼:
Names Default To Here( 1 );
dt_data = Open( "[filepath, no issues here]" );
dt_manifest = Open( "[filepath, no issues here]" );
Summarize( dt_data, IDs = by( :ID ) ); //this finds all the unique IDs in the data file, which we will need //[no issues here]
//First, populate the temporary data structure--associative array--from the data file which we will then copy over to the manifest file.
For( i = 1, i <= N Items( IDs ), i++,
ID = IDs[i];
data_array = Associative Array( {"data1", "data2", "data3"}, {{}, {}, {}} ); //it appears in the print statements we get 3 copies, indicating this loop works
For( data = data_array << First, !Is Empty( data ), data = data_array << Next( data ), //looping through data_array's keys is clunky but done this way in JMP
Write( ID ); //just a check; works
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data); //does not work
//...continue with further code to transfer from LBCM_array to manifest
);
);我擦洗了它所以它是機密的(不用擔心監視公司信息;))同時保留結構和信息(名稱“a”名稱,標籤到標籤)。
我現在的問題是這一行:
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
它拋出錯誤信息
.
Name Unresolved: Run date in access or evaluation of 'Run date' , :Run date/*###*/
In the following script, error marked by /*###*/
...
data_array[data] = :Run date/*###*/ <<WHERE></WHERE>
:Run date 是我的數據表(特別是 dt_data)中帶有實驗運行日期的數據列(標題)。 我正在嘗試將這些傳輸到第二個文件,因為每個數據點都應該收集三次/三次,這就是為什麼 data_array 在初始化時具有三個鍵和三個空值的原因。 這就是數據所在的位置,這個關聯數組 (data_array)。 然後它被轉移到 dt_manifest 但這是為了稍後,一旦這部分工作。
現在看來我無法在線訪問
data_array[data] = :Run date << Where(:ID == ID & :Timepoint == data);
我感興趣的行和列的適當選擇。 在這個時間點,問題陳述是否足夠清楚,聽眾中的任何人都可以參與並提供解決方案或貢獻,以了解如何以更語法(並且可能語義)正確的方式指定如何選擇我的數據子集對(來自 data_dt)感興趣?
不用擔心轉置問題。 我稍後會處理這個問題,老實說,一旦數據在 aa(關聯數組)中,這應該很容易。 此時我還在學習如何操作行/列選擇、數據表的子集等相關問題。
還有一點要注意:如果日期、數據和數組混在一起看起來很奇怪,那很可能是因為我為數據列或相關數據實體的清理/匿名化標題/標籤選擇了糟糕的名稱,以保護我公司的秘密安全。 我會說,在整個過程中我仍然是新手,我寧願為了安全起見而犯錯。
我將繼續從頭開始解決這個問題。
非常感謝,
麥克風
回复:使用轉置將數據子集從一個表移動到第二個表的列謝謝你,布雷迪。回复:使用轉置將數據子集從一個表移動到第二個表的列你好,
歡迎來到社區! 很抱歉,您在尋求幫助時在其他板上有過負面經歷。 儘管 JMP 用戶社區是一個熱情好客且樂於助人的地方,但也有一些“最佳實踐”可以最大限度地提高您獲得所需信息的機會。
問具體的問題,反之更籠統的問題,如果你能做到這一點,那就是要走的路——儘管我確實意識到有時候一個人“不知道他不知道什麼”。 發布大量偽代碼可能會嚇跑人們……如果您不能以其他方式提出您的問題,那麼附上“之前”和“之後”文件以及屏幕截圖將大有幫助,這樣觀眾就會有具體的了解“開始”表(或文本數據)和“完成”表的示例。 在這種特殊情況下,這肯定會產生真正的影響。 如果您必須“清理”數據集,那很好(最好,真的)。 只要你試圖說明的觀點仍然存在,就很好。
如果您提出具體的、有針對性的問題並附上說明性文件和屏幕截圖,那麼這裡的許多人很可能會跳出來提供幫助。 我能想到不止幾個無法真正抗拒它的副手!
乾杯,
布雷迪