sum function in the Factory
The sum function returns the sum of the column, evaluated within groups defined by the group parameter if required.
Parameters Parameter Description column The attribute used to evaluate the sum. Multiple attributes can be specified, as long as they are enclosed in double brackets, i.e. column((column1, column2)). In this occurrence, the sum will be calculated by row. The column parameter is mandatory. group The attribute by which you want to group your results. If this parameter is a list, then the column parameter can’t be a list. Example The following example uses the Students Performance dataset. Description Screenshot In this example, we want to sum the values of the writing score attribute. Add a new attribute, then type the following formula: The attribute has been filled with the sum of all the values in the writing score attribute. If you want, you can choose to group the results. In this example, we want our results to be grouped by the test preparation course attribute’s values. The formula becomes: The results can be read as follows: The sum of the writing score for those who took no preparation course ('none') is 41412. The sum of the writing score for those who completed the preparation course is 26642. When the column value is a list, the formula considers the single rows of the attributes, so it sums considering the chosen attributes in rows. For example, if we want to know the sum of the math score, writing score, reading score of the student in row 1, the formula becomes: The results can be read as follows: The student in row 1, female, group B, parental level of education bachelor’s degree, standard lunch and no test preparation course has an overall score of 218. The student in row 4, male, group A, parental level of education associate’s degree, free/reduced lunch and no test preparation course has an overall score of 148.sum(column, group)
sum($"writing score")
sum($"writing score",$"test preparation course")
sum(($"math score",$"writing score",$"reading score"))