将一张表中的列数据添加到已有的表中你好,
我正在尝试将一个输出表(称为“输出”)中的列数据添加到现有表(称为“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") )
);