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

Implement separate_longer_*() and separate_wider_*() #57

Open
etiennebacher opened this issue Nov 15, 2023 · 0 comments
Open

Implement separate_longer_*() and separate_wider_*() #57

etiennebacher opened this issue Nov 15, 2023 · 0 comments
Labels
feature upstream This requires changes in polars or in a tidyverse package.

Comments

@etiennebacher
Copy link
Owner

etiennebacher commented Nov 15, 2023

If they become generics one day: tidyverse/tidyr#1534

library(tidypolars)
#> Registered S3 method overwritten by 'tidypolars':
#>   method          from  
#>   print.DataFrame polars
library(polars)
library(tibble)

df <- tibble(id = 1:4, x = c("x", "x y", "x y z", NA))
pl_df <- as_polars_df(df)

df
#> # A tibble: 4 × 2
#>      id x    
#>   <int> <chr>
#> 1     1 x    
#> 2     2 x y  
#> 3     3 x y z
#> 4     4 <NA>
pl_df
#> shape: (4, 2)
#> ┌─────┬───────┐
#> │ id  ┆ x     │
#> │ --- ┆ ---   │
#> │ i32 ┆ str   │
#> ╞═════╪═══════╡
#> │ 1   ┆ x     │
#> │ 2   ┆ x y   │
#> │ 3   ┆ x y z │
#> │ 4   ┆ null  │
#> └─────┴───────┘

tidyr::separate_longer_delim(df, x, delim = " ")
#> # A tibble: 7 × 2
#>      id x    
#>   <int> <chr>
#> 1     1 x    
#> 2     2 x    
#> 3     2 y    
#> 4     3 x    
#> 5     3 y    
#> 6     3 z    
#> 7     4 <NA>

pl_df$with_columns(pl$col("x")$str$split(by = " "))$explode("x")
#> shape: (7, 2)
#> ┌─────┬──────┐
#> │ id  ┆ x    │
#> │ --- ┆ ---  │
#> │ i32 ┆ str  │
#> ╞═════╪══════╡
#> │ 1   ┆ x    │
#> │ 2   ┆ x    │
#> │ 2   ┆ y    │
#> │ 3   ┆ x    │
#> │ 3   ┆ y    │
#> │ 3   ┆ z    │
#> │ 4   ┆ null │
#> └─────┴──────┘
@etiennebacher etiennebacher added upstream This requires changes in polars or in a tidyverse package. and removed future labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature upstream This requires changes in polars or in a tidyverse package.
Projects
None yet
Development

No branches or pull requests

1 participant