你好 ,
我正在尝试使用变量类型从每个 ID 的多行创建一个变量(type2)。 我想隐藏一张这样的桌子:
到:
其中 type2 是:
如果 type 总是 A 则 type2=A;
如果类型始终为 B,则 type2=B;
如果 type 是 A 和 B 的组合,则 type2=C;
谢谢
有很多方法可以做到这一点。 我会计算类型在 ID 中出现的次数,如果它与 ID 在数据中出现的数量相同,那么您就知道它是唯一的类型。
用公式总结:
Names Default To Here(1);
dt = New Table("From",
Add Rows(8),
New Column("ID", Numeric, "Nominal", Format("Best", 12), Set Values([1, 1, 1, 2, 2, 3, 3, 3])),
New Column("type", Character(16), "Nominal", Set Values({"A", "A", "B", "A", "A", "B", "B", "B"}))
);
dt_summary = dt << Summary(
Output table("To"),
Group(:ID),
N(:type),
Subgroup(:type),
Freq("None"),
Weight("None"),
statistics column name format("column"),
Link to original data table(0)
);
dt_summary << New Column("type2", Character, "Nominal",
<< Set Each Value(
If(:"type, A"n == 0, "B",
:"type, B"n == 0, "A",
"C"
)
)
);和其他使用 Col Sum 和 Select 重复行:
Names Default To Here(1);
dt = New Table("From",
Add Rows(8),
New Column("ID", Numeric, "Nominal", Format("Best", 12), Set Values([1, 1, 1, 2, 2, 3, 3, 3])),
New Column("type", Character(16), "Nominal", Set Values({"A", "A", "B", "A", "A", "B", "B", "B"}))
);
dt << New Column("type2", Character, Nomimal, Formula(
If(Col Sum(1, :ID) == Col Sum(1, :ID, :type),
:type,
"C"
)
));
wait(1);
dt:type2 << Delete Formula;
wait(1);
dt << Select Duplicate Rows(Match(:ID, :type2));<BR />wait(1);<BR />dt << Delete Rows;有关函数的更多信息,尤其是 Col Sum,请参见脚本索引。
你好,
看起来您的表格可能按 :ID 和 :type 排序。 如果是,或者如果您愿意对其进行排序,您可以利用这一点并对 :type2 列使用(相对)简单的公式:
If( :type[Col Min( Row(), :ID )] == :type[Col Max( Row(), :ID )],
:type,
"C"
)
干杯,
布雷迪