將一張表中的列資料加入到已有的表中你好,
我正在嘗試將輸出表(稱為“輸出”)中的列資料添加到現有表(稱為“Stanmore 和Lam”),但是當我使用join 命令時,它會創建一個空的新輸出表。 我的程式碼如下:
output = New Table( "Output",
AddRows( 1 ),
New Column( "Y (coronal) mm", Numeric, Continuous ),
New Column( "X (sagittal) mm", Numeric, Continuous )
);
:"Y (coronal) mm" << addRows( 1 );
:"X (sagittal) mm" << addRows( 1 );
:"Y (coronal) mm"[1] = ymax;
:"X (sagittal) mm"[1] = xmax;
dt2 = Open( "Stanmore and Lam.jmp" );
dt2 << Join(
With( Data Table( output ) ),
By Matching Columns( :"Y (coronal) mm" = :"Y (coronal) mm", :"X (sagittal) mm" = :"X (sagittal) mm" )
);
有沒有什麼方法可以簡單地將特定列中的行值添加到預先存在的列(兩個表具有不同的列數和行數),而無需手動將資料從一個表輸入到另一個表? 謝謝!
諾亞
回覆:將一張表中的列資料加入到已有的表中我可以透過將以下內容新增到您上面建議的程式碼中來設定參考:
toBeConcat = dt2 << Join(
With( Data Table( output ) ),
"Stanmore and Lam",
Update,
By Matching Columns(
:Name( "Y (coronal) mm" ) = :Name( "Y (coronal) mm" ),
:Name( "X (sagittal) mm" ) = :Name( "X (sagittal) mm" )
)
);
dt2 << Concatenate( toBeConcat, append to first table );
這 1) 更新了我的輸出格式以適應 Stanmore 和 Lam 表的格式,2) 將該輸出連接到原始表,而不建立新的輸出資料表。 所以現在程式碼完全符合我的需要。 非常感謝你的幫忙!
回覆:將一張表中的列資料加入到已有的表中我對“更新”選項的評論將解決這個問題。 只需添加
更新,
到您的加入,它將處理您想要的內容。
回覆:將一張表中的列資料加入到已有的表中感謝您的快速回覆! 這種語法更適合用我需要的值填入新表。 這仍然會產生一個全新的表,所以有什麼方法可以設定對它的引用,以便我可以將它連接到我的“Stan and Lanmore”表? 再次感謝!
諾亞
回覆:將一張表中的列資料加入到已有的表中這是對您的腳本的修改,以使其語法正確。 我無法說出您的邏輯,因為您沒有包含變數 xmax 和 ymax 是什麼,也沒有包含資料表「Stanmore 和 Lam」包含的內容
output = New Table( "Output",
AddRows( 1 ),
New Column( "Y (coronal) mm", Numeric, Continuous ),
New Column( "X (sagittal) mm", Numeric, Continuous )
);
// You don't add rows to columns, you add rows to data tables. But since you have allready added
// a row to the new data table, you don't need to add a second row
//:"Y (coronal) mm" << addRows( 1 );
//:"X (sagittal) mm" << addRows( 1 );
// The proper form for what you are trying to do is:
// :Name("complex name")
//:"Y (coronal) mm"[1] = ymax;
//:"X (sagittal) mm"[1] = xmax;
:Name("Y (coronal) mm")[1] = ymax;
:Name("X (sagittal) mm")[1] = xmax;
dt2 = Open( "Stanmore and Lam.jmp" );
dt2 << Join(
With( Data Table( output ) ),
// You may want to use the "UPDATE" option to copy the matching rows from the joining table to the
// initial table
// Update,
// The proper naming structure has been replaced here too
By Matching Columns( :Name("Y (coronal) mm") = :Name("Y (coronal) mm") , :Name("X (sagittal) mm") = :Name("X (sagittal) mm") )
);