tidyblocks
tidyblocks copied to clipboard
Preparing grouped summaries: expectation and replication
I am trying to replicate the output of the following R Code chunk in TidyBlocks:
library(palmerpenguins)
library(dplyr)
penguins %>%
group_by(species) %>%
summarise(species_count = n())
#> `summarise()` ungrouping output (override with `.groups` argument)
#> # A tibble: 3 x 2
#> species species_count
#> <fct> <int>
#> 1 Adelie 152
#> 2 Chinstrap 68
#> 3 Gentoo 124
Created on 2020-10-30 by the reprex package (v0.3.0)
I have managed to do so with the following Block:
I expected the following to work:
Question 1: Why is the output of summarise not collapsed into 2 columns and 3 rows? It seems counterintutive that a new column is added to the original data instead.
Question 2: How do I name the output object? On the right pane und the tab "Results" I see "unnamed 1" and have not managed to figure out how to change this name.
- We add a label to show groups so that users can re-group if they want to - given the block metaphor, we couldn't find another visual way to do this. Happy to discuss alternatives.
- The "save as" block will save its input under whatever name you choose and pass it to the output unmodified.
Thanks, should have seen the "Save as" block.
On 1: Could you elaborate on the re-grouping? I am not sure I understand the benefit from a user perspective.
Would you also use of the following code block sequence to get the output that I re-produced above with R? I want to make sure that I am not missing something and would get to this output in a simpler way.