如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?你好,
我有一张包含重复连续实验的数据表。因此数据已经堆叠。我有一列,其中每个新实验都以 1 开始,然后是 2,依此类推,直到最后一次测量。我想创建一个带有实验编号的新列,因此每次另一列以 1 开头时,这都是另一个实验的开始。
我曾尝试在 AI 的帮助下编写此脚本,但没有成功。希望有人能帮助我。
dt = 当前数据表();
// 用于识别新实验的列
experimentIdentifier = Column(dt, "Column1"); // Column1 包含从 1 到 100 不断重复的数字。
// 为样本数字创建新列
dt << 新列(“SampleNumber”,数字);
// 初始化变量
当前实验 = 实验标识符[1];
样本数量 = 1;
// 使用显式行索引迭代每一行
对于(i = 1,i <= N 行(dt),i++,
如果(experimentIdentifier[i] != currentExperiment,
// 新的实验开始,重置样本数
当前实验 = 实验标识符[i];
样本数量 = 1;
,
// 否则,增加样本数
样本数++;
(英文):
// 将样本编号分配给新列
dt:样本编号[i] = 样本编号;
(英文):
自动化和脚本数据混合和清理回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?创建一个新列并将其设置为公式:
Col Cumulative Sum( 1, :Column 1 )
第 1 列是包含测量数字的列。
脑子放屁。
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?Length( Loc( :Column 1[1 :: Row()], 1 ) )
这个公式有效。
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?您可以使用 Col Cumulative Sum(),但它不太漂亮。
Col Cumulative Sum( If( :Column 1 == 1, :Column 1, 0 ) )
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?我不明白如何在脚本中使用它。
我也尝试过这个,但到目前为止,我的新列中的所有行的值都是 1。您能看出哪里出了问题吗?
dt = 当前数据表 () << 新列("实验编号",
数字,
公式(
If( Row() == 1, 1, // 将第一行的实验编号初始化为 1
If( :Point No. == 1 & Lag(:Point No.) != 1, Lag(:Experiment No) + 1, // 如果“Point No.”重置为 1,则增加实验编号
Lag(:实验编号, 1) // 否则,保持相同的实验编号
)
)
)
(此处似有缺失,请提供更正后的文本)。
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?你好@WhiteCow2000 ,
我尝试了一种方法,先找到出现“1”的位置,用递增的数字标记每个位置,然后复制“填充”>“用上一个值替换缺失值”选项(可以在 JMP 中手动完成)。为了更加灵活,我添加了一个窗口供您选择要测量的列。
Names Default To Here( 1 );
dt = current data Table ();
dt << Clear Column Selection();
//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way then it will adapt to that so be careful.
//Window to select the column with repeats
nw = New Window( "Launch Dialog",
<<MODAL></MODAL>
<P>您可以在 JSL 中键入精确列名的脚本的简单版本如下:<BR /><BR /></P>
<CODE class=" language-jsl">Names Default To Here( 1 );
dt = current data Table ();
//This will work to find the instance where the lowest number (1 in this case) appears in the row order, if the rows are sorted in any way
//Window to select the column with repeats
//Add a column to track experiment number
dt<<NEW column=""></NEW>
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?AI 的 JSL 表现很差。应用我的解决方案很简单。另外,我试过你最后那个公式,效果很好。
dt = New Table( New Column( "Point No.", Set Values( Repeat( 1 :: 100, 4 ) ) ) );
dt << New Column( "Experiment No", Numeric, Formula( Length( Loc( :Point No.[1 :: Row()], 1 ) ) ) );
dt << New Column( "Experiment No", Numeric, Formula( Col Cumulative Sum( If( :Point No. == 1, :Point No., 1, 0 ) ) ) );
dt << New Column( "Experiment No",
Numeric,
Formula(
If( Row() == 1,
1, // Initialize experiment number as 1 for the first row
If( :Point No. == 1<SPAN> & Lag(:Point No.) != 1</SPAN>,
Lag( :Experiment No ) + 1, // Increment experiment number if "Point No." resets to 1
Lag( :Experiment No, 1 ) // Otherwise, keep the same experiment number
)
)
)
);

回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?非常感谢您的帮助!现在它既能用于 If 公式,也能用于 Length 公式了!
回复:如何在具有堆叠重复连续数据的数据表中创建带有实验编号的新列?几周后回到这个帖子,分享一个类似问题的好解决方案,我认为使用更简单的公式可能会更好:
已解决:如何获取新列来填充大型数据集中的多个循环或循环...... - JMP 用户社区