proper nest/unnest functions

Open
#3,672 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start by reproducing the grouped data.table expression and comparing its result with the shown tibble nest() example. Read the issue discussion to determine whether proper nest() and unnest() functions have an agreed API; the work is done only when the intended equivalent behavior and scope are defined.

Written by the indexing model from the issue text.

Description

feature request

Hello,

I am trying to get the equivalent of nest() / unnest() in data.table and I wonder if a new function would make more sense. Consider this little example


tibble(group = c(1,1,1,2,2,2),
      val = c('hello', 'world','hello', 'world','hello', 'world'),
      col = c(1,2,3,4,5,6)) %>% 
  group_by(group) %>% nest() %>% 
  mutate(newval = group + 1)

# A tibble: 2 x 3
  group data             newval
  <dbl> <list>            <dbl>
1     1 <tibble [3 x 2]>      2
2     2 <tibble [3 x 2]>      3

I am not sure the same can be done with data.table. Look at the mysterious output I get after this. Am I missing something?


mydf[, list(listcol=list(data.table(val, col))), by=group][
  , newval := group + 1]
   group    val newval
1:     1 <list>      3
2:     1 <list>      3
3:     1 <list>      3
4:     2 <list>      3
5:     2 <list>      3
6:     2 <list>      3
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.