Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pivot_longer() to work on unbalanced data #467

Open
markfairbanks opened this issue Feb 19, 2024 · 0 comments
Open

Allow pivot_longer() to work on unbalanced data #467

markfairbanks opened this issue Feb 19, 2024 · 0 comments
Labels
feature a feature request or enhancement

Comments

@markfairbanks
Copy link
Collaborator

This didn't work previously, but now it does

library(dtplyr)
library(dplyr)
library(tidyr)
library(data.table)

df <- tibble(x_5 = 5, x_6 = 6, y_7 = 7, y_8 = 8)

df %>%
  pivot_longer(everything(), names_to = c(".value", "id"), names_sep = "_")
#> # A tibble: 4 × 3
#>   id        x     y
#>   <chr> <dbl> <dbl>
#> 1 5         5    NA
#> 2 6         6    NA
#> 3 7        NA     7
#> 4 8        NA     8

data.table(df) %>%
  melt(measure.vars=measure(value.name, id, sep="_"))
#>        id     x     y
#>    <char> <num> <num>
#> 1:      5     5    NA
#> 2:      6     6    NA
#> 3:      7    NA     7
#> 4:      8    NA     8

data.table(df) %>%
  melt(measure.vars=measurev(list(value.name=NULL, id=NULL), sep="_"))
#>        id     x     y
#>    <char> <num> <num>
#> 1:      5     5    NA
#> 2:      6     6    NA
#> 3:      7    NA     7
#> 4:      8    NA     8

df %>%
  lazy_dt() %>%
  pivot_longer(everything(), names_to = c(".value", "id"), names_sep = "_") %>%
  collect()
#> Error in `pivot_longer()`:
#> ! `data.table::melt()` doesn't currently support melting of unbalanced datasets.
@markfairbanks markfairbanks added the feature a feature request or enhancement label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant