我不确定在 JMP 14 中复制列的最快方法是什么。
相同的信息(数据、元数据、公式),但标题不同(例如,列名称副本)。
此代码片段将返回当前选定列的名称
colName = (current data table() << get selected columns)[1];
对于那些使用此功能的人来说仅供参考 - 我一直在定期使用此功能,但已将其挂在较大的数据表(> 100k 行)上。我还没有彻底调试 - 但我确实发现这里克隆列线程(基本上相同,除了脚本没有 char() 转换并且没有替换 - 我使用表达式设置命名)速度快了约 5 倍,我希望不会在任何导致我挂起的极端情况下死亡。我正在将我的插件切换为使用基于此的东西,并希望它不太可能崩溃。
https://community.jmp.com/t5/Discussions/clone-a-column/td-p/15644
最简单的方法是使用 eval(:col << Get Script)。您将获得该列的副本,末尾带有一个整数,以为其指定一个唯一的名称。您需要确保要对其执行操作的表是当前表。
这是一个方便的函数,您可以在脚本中使用它,让您命名生成的新列并指定数据表。唯一必需的参数是第一个参数 colname。您可以指定一个数据表,但否则它将采用 Current Data Table()。如果不指定名称,则返回原始列名+“-复制”。
Names Default to Here(1);
DupCol = function({colname, new = "", dt = Current Data Table() },
col = Column(dt, colname);
if(IsMissing(new), new = colname||" - Copy");
col_script = char(col << Get Script);
col_script = substitute(col_script, "New Column", "dt << New Column");
col_script = substitute(col_script, colname, new);
eval(parse(col_script));
);
我将使用 Football 示例数据(和 Big Class 来显示该函数的稳健性)进行说明:
football_dat = Open("$SAMPLE_DATA/Football.jmp");
DupCol("Height"); //Produces copy of Height named "Height - Copy"
DupCol("Height", new = "Height Again"); //Produces copy of Height named "Height Again"
Open("$SAMPLE_DATA/Big Class.jmp"); //just to show robustness since this data table also has a column named "height"
//Different ways to specify the data table if not wanting to assume Current Data Table
DupCol("Height", new = "Height Once More", dt = Data Table("Football") );
DupCol("Height", new = "Height Last Time", dt = football_dat );
从点击的角度来看,我知道的最短方法仍然是两步过程。您可以使用典型的 Ctrl+C/Ctrl+V 操作复制/粘贴数据。您可以通过右键单击要复制的列的列标题 > 复制列属性,右键单击新复制列 > 粘贴列属性来复制/粘贴元数据(列属性)。