如何為具有不相等行的多個變量分配和增加迭代計數?大家好。
我試圖創建一個列,該列根據“Comment = End of Cycle”列分配迭代編號(數字和連續),並為相同的 SN 遞增它。 每個SN的數據點數量並不相同。
例如。
對於 SN =“A”,第 1-9 行:迭代 =1,第 10-16 行迭代 =2
對於 SN =“B”,第 17-27 行:迭代 =1,第 28-36 行迭代 =2,依此類推...
使用 Row () 函數嘗試了一些變體,但沒有成功。 有人可以對此提供一些指導嗎?

高級統計建模消費者和市場研究回复:如何為具有不相等行的多個變量分配和增加迭代計數?感謝您的推薦。 數據按 SN 和日期排序,這使得它更容易。
回复:如何為具有不相等行的多個變量分配和增加迭代計數?這是公式的其他選項
Col Cumulative Sum(
Col Min(Row(), :SN) == Row() | Lag(:Comment) == "End of Cycle",
:SN
);
回复:如何為具有不相等行的多個變量分配和增加迭代計數?@sumanthcb141977
我唯一的另一個想法是使用一個額外的桌子。也許可以使用新表,將其值用作位置標記。這將允許您擁有一個表或數值,以及另一個帶有類別的表或數值。這將減少數字和類別之間的硬轉換。
回复:如何為具有不相等行的多個變量分配和增加迭代計數?@sumanthcb141977
嘗試以下操作。它不穩健,需要先按 SN 再按日期對數據進行排序。
New Table( "Untitled",
Add Rows( 36 ),
New Column( "SN",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B"}
)
),
New Column( "Comment",
Character,
"Nominal",
Set Values(
{"Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle",
"End of Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle",
"End of Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle",
"Cycle", "Cycle", "Cycle", "Cycle", "End of Cycle", "Cycle", "Cycle",
"Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle", "Cycle"}
)
),
New Column( "iteration count",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula(
If(
Row() == 1, 1,
Lag( :SN ) == :SN & Lag( :Comment ) == "Cycle",
Lag( :iteration count ),
Lag( :SN ) == :SN & Lag( :Comment ) == "End of Cycle",
Lag( :iteration count ) + 1,
Lag( :SN ) != :SN & Lag( :Comment ) == "End of Cycle", 1
)
),
Set Selected
)
)
也許其他人有更強大的索引方法。
回复:如何為具有不相等行的多個變量分配和增加迭代計數?感謝您的回复。 抱歉,必須更具體。 我不需要名為迭代計數的附加列。 我希望迭代的公式分配一個數字並根據“週期結束”註釋遞增它。 下面是我想要的迭代列的圖像。

我根據請求附加 jmp 文件。
回复:如何為具有不相等行的多個變量分配和增加迭代計數?你好@sumanthcb141977
請嘗試以下操作。
New Table( "Untitled",
Add Rows( 36 ),
New Column( "SN",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B"}
)
),
New Column( "iteration",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2]
)
),
New Column( "iteration count",
Numeric,
"Nominal",
Format( "Best", 9 ),
Formula( Col Cumulative Sum( 1, :SN, :iteration ) )
)
)
如果這不是您要查找的內容,請提供數據表,以便更容易解決。
讓我們知道它是否有效