rStats.js v1.3.0
    Preparing search index...

    Function aggregate

    • The function applied to the values of each group, as a data frame. Equivalent to R's aggregate().

      Formula form, aggregate(formula, data, fun): "y ~ g", "y ~ g + h", "cbind(y, z) ~ g" or ". ~ g" (every column not on the right). The grouping variables are all the variables of the right-hand side in order of first appearance, whatever its operators ("y ~ g:h" and "y ~ g * h" group by g and h); "y ~ ." groups by every column not summarised, and "y ~ 1" gives one row without a grouping column. The rows with a missing value in any variable of the formula are dropped first. Data frame form, aggregate(x, by, fun): the columns of x summarised by the label columns of by (its keys name them); only the rows with a missing label are dropped, so fun sees the missing values of x.

      The result has the grouping columns first (with the labels as in the data), then one column per summarised column, and one row per non-empty combination of the groups (the first factor varying fastest). When fun returns k > 1 values, a summarised column y becomes y.1, ..., y.k (an array) or y.<name> (an object of numbers).

      Parameters

      Returns DataFrame

      aggregate("y ~ g", { y: [1, 2, 3, 4], g: ["b", "a", "b", "a"] }, mean); // { g: ["a", "b"], y: [3, 2] }
      
    • The function applied to the values of each group, as a data frame. Equivalent to R's aggregate().

      Formula form, aggregate(formula, data, fun): "y ~ g", "y ~ g + h", "cbind(y, z) ~ g" or ". ~ g" (every column not on the right). The grouping variables are all the variables of the right-hand side in order of first appearance, whatever its operators ("y ~ g:h" and "y ~ g * h" group by g and h); "y ~ ." groups by every column not summarised, and "y ~ 1" gives one row without a grouping column. The rows with a missing value in any variable of the formula are dropped first. Data frame form, aggregate(x, by, fun): the columns of x summarised by the label columns of by (its keys name them); only the rows with a missing label are dropped, so fun sees the missing values of x.

      The result has the grouping columns first (with the labels as in the data), then one column per summarised column, and one row per non-empty combination of the groups (the first factor varying fastest). When fun returns k > 1 values, a summarised column y becomes y.1, ..., y.k (an array) or y.<name> (an object of numbers).

      Parameters

      Returns DataFrame

      aggregate("y ~ g", { y: [1, 2, 3, 4], g: ["b", "a", "b", "a"] }, mean); // { g: ["a", "b"], y: [3, 2] }