The ave function in R is used to group a vector by a factor variable and then calculate the mean within each group. Unfortunately, there is no built-in ave function in Javascript. However, you can write your own function to perform a similar task.
Here's an example of how to write a function in Javascript that operates similarly to ave in R:
index.tsx542 chars26 linesYou can use the function by passing in an array to group and a parallel array of factor levels to group by. For example:
index.tsx180 chars5 lines
This example groups the array arr by the corresponding group values in groupBy, and then calculates the mean within each group. The result is an array of means that corresponds to the original order of arr.
gistlibby LogSnag