Post

For grouped summaries in #rstats, do you use group_by() + summarize() or the .by argument in summarize()?

2 reposts7 likes

Hmm. What's the rationale for using group_by/summarize/ungroup with collabs? I'm trying to switch to `.by` and especially trying to teach with `.by`: shorter, safer [leftover groupings can cause problems]); cases where you want to `group_by()` to do several operations in a row are rarer ...

2. The way it's written within a piped sequence is opposite to the order it was: reading top to bottom left to right we compare group=>summarize to summarize=>group. I'd rather write out summarize(.by = group, a = mean(x)) But that's not the order in the function, and also...

For me: `.by`, all the way and in all functions, even in`slice_sample()` where it is annoyingly called `by`. But `.by` deserves its own row.

Usually A. I like the .by approach in theory. What keeps me using group_by() is that that's resilient to any prior grouping in my workflow, whereas .by breaks if the dataframe is already grouped.

If I want to use .by, I would need to totally commit to making that my workflow. No group_by(), or at least none without immediately ungroup()ing. And that's a relatively heavy cognitive lift.