DolphinDB: how to quickly calculate the correlation of a column with the other columns in a table?

21 Views Asked by At

Suppose there is a table containing a column “x“ and the other 10 columns from “y1“ to “y10“. I want to calculate the correlation of column “x“ with the other 10 columns. Is there an easy way to achieve this in DolphinDB?

1

There are 1 best solutions below

0
YaN On

You can use the each- higher-order functions (e.g., each, eachLeft, eachPre) to iterate over columns “y1“, “y2“…, and “y10“. The following script uses the :R / eachRight function with the corr function to calculate the correlation of column "x" with the other columns.

corr:R(table.x. table[`y1`y2...])