Is there a way to suppress "header" information from group_by() and summarise()?

I would like to be able to suppress some of the header information from summarize. For example,

ACS %>% group_by(EDUCD, major) %>%
summarise(avg = mean(INCTOT, na.rm= TRUE),
med = median(INCTOT, na.rm= TRUE))

gives me

# A tibble: 12 x 4
# Groups: EDUCD [4]
EDUCD major avg med
<fct> <chr> <dbl> <dbl>
1 Bachelor's accounting 82201. 59000
2 Bachelor's econ 95268. 60000
3 Bachelor's other BA 63287. 46200
4 Master's accounting 108625. 80000

I would like the lines with the information about the tibble size and the groups to go away. (I also wouldn't mind getting rid of the line beginning <fct>.

This tells you how:
Summarise each group to fewer rows — summarise • dplyr (tidyverse.org)

On the second point I'm not sure why you are bothered by how the console output is formatted. If you wish to use the output in results then you can do so without using the console, e.g. by exporting the data or by using a markdown document.

I'm not trying to reduce the number of rows. I'd like the headers

# A tibble: 12 x 4
# Groups: EDUCD [4]

and

<fct> <chr> <dbl> <dbl>

to go away.

My problematic output is from a pdf created using R Markdown.

Is there any feature of tibble that you in particular want ? because it seems like you just want a plain data.frame
Here is an example with the first 6 rows of iris as example

library(tidyverse)

(hiris <- head(iris))

(tibble(hiris))

(tibble(hiris) %>% as.data.frame())

identical(hiris,
          tibble(hiris) %>% as.data.frame())

That completely solves my problem. Never occurred to me to "un-tidyverse" it!

You might want to use xtable to make tables in RMarkdown in pdf.

That is a good suggestion. But in fact my use of RMarkdown here is to make slides for teaching. I'm trying to show students the use of group_by() and summarise(). So the use of markdown is kind of incidental to my goal.

In my opinion, if that's the use case, don't suppress anything. That will be confusing to them if they run the code and see different output.

That's not what I indicated. The answer to your first question is in the link I provided.

I did read the link. I don't see the answer there. Every example there includes the header lines I want to go away.

I am perfectly willing to believe that I'm missing something though...

This part:

In addition, a message informs you of that choice, unless the result is ungrouped, the option "dplyr.summarise.inform" is set to FALSE , or when summarise() is called from a function in a package.

I had missed that, so thanks. But I still seem to be missing something.

> options(dplyr.summarise.inform=FALSE)
> ibt_clean %>% group_by(nationalityRecode) %>% summarise(n())
# A tibble: 3 x 2
  nationalityRecode `n()`
  <fct>             <int>
1 usa                  13
2 not_usa              32
3 other                 5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.