Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Since .key is deprecated how it is possible to rename the data column in nest()?

Before .key was deprecated I did this:

library(tidyverse)

mtcars %>% group_by(cyl) %>% nest(.key = "my_name")

The help of nest() points out that now this is performed using tidy select, but I don't know how.

like image 421
danilinares Avatar asked Oct 21 '25 10:10

danilinares


1 Answers

You can use the new nest_by function in dplyr 1.0.0 which works similar to what you had previously with nest.

library(dplyr)
mtcars %>% group_by(cyl) %>% nest_by(.key = "my_name")

#   cyl             my_name
#  <dbl> <list<tbl_df[,10]>>
#1     4           [11 × 10]
#2     6            [7 × 10]
#3     8           [14 × 10]

You can also do the same without grouping.

mtcars %>% nest_by(cyl, .key = "my_name")
like image 73
Ronak Shah Avatar answered Oct 23 '25 00:10

Ronak Shah