Hello everybody,
I have test groups A and B, 4 different items, Param2 (being the maximum of Param1 values) saved in the first cell of corresponding item. The values of Param2 are sometimes provided per hand. Now I would like to calculate the median of Param2 for each test group and save it again
in the first cell where each test group starts, like in the table below. I would appreciate for hints how I can do that in script.
Thank you and best regards.
Use Col Median to calculate median over groups. Then combine that with if-statement which checks for first row of the group using Col Min
Example:
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(8),
New Column("Group", Character, "Nominal", Set Values({"A", "A", "A", "A", "B", "B", "B", "B"})),
New Column("Param", Numeric, "Continuous", Format("Best", 12), Set Values([5, ., ., 6, 3, ., 2, .])),
New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., ., ., ., ., .]))
);
dt << New Column("Med", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :Group),
Col Median(:Param, :Group)
,
.
)
));
Use Col Median to calculate median over groups. Then combine that with if-statement which checks for first row of the group using Col Min
Example:
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(8),
New Column("Group", Character, "Nominal", Set Values({"A", "A", "A", "A", "B", "B", "B", "B"})),
New Column("Param", Numeric, "Continuous", Format("Best", 12), Set Values([5, ., ., 6, 3, ., 2, .])),
New Column("Column 4", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., ., ., ., ., .]))
);
dt << New Column("Med", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :Group),
Col Median(:Param, :Group)
,
.
)
));
Hi,
thank you for suggestion. It is working, however I noticed that I have in data some other even high-level groups for which median within lower-level groups need to be calculated. I slightly adapted the if statement:
Best regards
dt << New Column("Med", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :High_level_Group, :Low_level_Group),
Col Median(:Param, :High_level_Group, :Low_level_Group)
,
.
)
));