How would I create a nested list-column of codes using tidyverse?

Hi,

In the below example, I would like to use tidyverse to create a list-column of codes for each carrier. So the dataset would end up with each row being on an airline basis, and a column for the carrier and a list-column for the flights

 library(tidyverse)
  library(nycflights13)
  
  nycflights13::flights |> 
    head(100) |> 
    select(carrier, flight) |> 
    mutate(flight = as.character(flight))

image

nest_by(carrier) from dplyr?

1 Like

This works, but maybe there is a more elegant way??

Depending on how you will use the list, you may want to stop at nest_by(). It gives a list column of tibbles while unnest_wider() has a list of vectors.

1 Like

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.