How to interpret dplyr message `summarise()` regrouping output by ‘x’ (override with `.groups` argument)?

I started getting a new message (see post title) when running group_by and summarise() after updating to dplyr development version 0.8.99.9003. Here is an example to recreate the output: library(tidyverse) library(hablar) df <- read_csv(“year, week, rat_house_females, rat_house_males, mouse_wild_females, mouse_wild_males 2018,10,1,1,1,1 2018,10,1,1,1,1 2018,11,2,2,2,2 2018,11,2,2,2,2 2019,10,3,3,3,3 2019,10,3,3,3,3 2019,11,4,4,4,4 2019,11,4,4,4,4”) %>% convert(chr(year,week)) %>% mutate(total_rodents = rowSums(select_if(., is.numeric))) %>% … Read more

Relative frequencies / proportions with dplyr

Suppose I want to calculate the proportion of different values within each group. For example, using the mtcars data, how do I calculate the relative frequency of number of gears by am (automatic/manual) in one go with dplyr? library(dplyr) data(mtcars) mtcars <- tbl_df(mtcars) # count frequency mtcars %>% group_by(am, gear) %>% summarise(n = n()) # … Read more

Extract a dplyr tbl column as a vector

Is there a more succinct way to get one column of a dplyr tbl as a vector, from a tbl with database back-end (i.e. the data frame/table can’t be subset directly)? require(dplyr) db <- src_sqlite(tempfile(), create = TRUE) iris2 <- copy_to(db, iris) iris2$Species # NULL That would have been too easy, so collect(select(iris2, Species))[, 1] … Read more

Use dynamic name for new column/variable in `dplyr`

I want to use dplyr::mutate() to create multiple new columns in a data frame. The column names and their contents should be dynamically generated. Example data from iris: library(dplyr) iris <- as_tibble(iris) I’ve created a function to mutate my new columns from the Petal.Width variable: multipetal <- function(df, n) { varname <- paste(“petal”, n , … Read more

data.table vs dplyr: can one do something well the other can’t or does poorly?

Overview I’m relatively familiar with data.table, not so much with dplyr. I’ve read through some dplyr vignettes and examples that have popped up on SO, and so far my conclusions are that: data.table and dplyr are comparable in speed, except when there are many (i.e. >10-100K) groups, and in some other circumstances (see benchmarks below) … Read more