1

Matlab seems to have a number of different code patterns for realizing SQL's GOUPBY aggregation of data. To me it seems that this makes it hard for best practice and code idioms to coalesce. Are there guidelines for which are best for which situations?

user36800
  • 2,019
  • 2
  • 19
  • 34
  • 1
    Stack Overflow is not the place to ask about "best practice" or "guidelines", those are opinion-based and therefore off topic. `rowfun` and `varfun` only work on tables, so if your data is non tabular then use `splitapply`, aside from that use them for their nuances. – Wolfie Jul 01 '19 at 15:33
  • Do `rowfun` or `varfun` really aggregate results based on groups? To me, the choice would rather be between `accumarray` and `splitapply` – Luis Mendo Jul 01 '19 at 16:07
  • @Wolfie: I hear what you mean about best practices in general, but here, it applies to very specific commands, e.g., "When would you use this over that?" – user36800 Jul 01 '19 at 16:55
  • @Luis Mendo: Yes, they take a set of gouping variables. I've stopped using `findgroups` and `splitapply`, and I'm wondering when they would be used. Even if there are fringe situations not covered by one command, it seems very odd that such an assortment of commands with overlapping functionality exists. Wondering if that's just the result of exploratory evolution on Matlab's part. – user36800 Jul 01 '19 at 16:57
  • @user36800 Interesting, I didn't know they could do that, thanks! – Luis Mendo Jul 01 '19 at 16:58
  • As I said, you'd want `findgroups` andn`splitapply` if your numeric and grouping data weren't in a table together – Wolfie Jul 02 '19 at 06:21
  • Aw gee. I gotta apologize. I was so focused on the comment about being off-topic that I didn't even see the rest of of it. A source of confusion in googling TMW pages is that the colloquial use of "table" encompasses arrays, while the TMW `table` class is not an array. From the help pages, I can see that by "non tabular", you mean that `findgroups` and `splitapply` support arrays. I wouldn't have noticed that in my usage, as I so seldomly use bare arrays (except as portions of `table`s). – user36800 Jul 03 '19 at 12:54
  • I'm guessing that `findgroups` & `splitapply` came first, then as TMW had opportunity to craft more convenient functions for `table`s, they brought in `rowfun` and `varfun`. Would you care to post your explanation as an answer? – user36800 Jul 03 '19 at 12:54

0 Answers0