Skip to content
Advertisement

calculate sum of squares with rows above

I have a dataset that looks like this:

JavaScript

I want to iterate through each row and calculate a sum of squares value for each row above (only if the Type matches). I want to put this value in the X.sq column.

So for example, in the first row, there’s nothing above. So only (-1.975767 x -1.975767). In the second row, there’s no FRUITS row above it, so it will just be -0.540979 x -0.540979. However, in the third row, when we scan all previous rows, we should find that FRUITS is already there. So we should get the last’s FRUIT’s ….. X_sq value and calculate a new sum of squares.

JavaScript

What would be an efficient way to do this?

JavaScript

EDIT:

JavaScript

Advertisement

Answer

Use:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement