我想按“z”列对表格进行分组,并使用脚本
corr:R(table.x. table[y1y2...]
计算每组中“x”列与“y1”、“y2”列...的相关性。如何在 DolphinDB 中实现这一点?
您可以使用
groups
函数按“z”列对表进行分组,该函数返回一个元组,其元素是“z”列中每个唯一值的索引。使用脚本 t @ groups(t.z, 'tuple')
返回代表每组记录的表,并使用 corr
函数计算每组中“y1”、“y2”和“y3”列的相关性,如下脚本所示:
t = table(1..10 as x, 1 1 1 1 2 2 2 2 2 2 as z, rand(1.0, 10) as y1, rand(1.0, 10) as y2, rand(1.0,10) as y3)
each(f->corr:R(f.x, f[`y1`y2`y3]), t @ groups(t.z, 'tuple'))