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

[FR] rowwise semantics for flattening data.frame #401

Closed
yutannihilation opened this issue Oct 31, 2017 · 1 comment
Closed

[FR] rowwise semantics for flattening data.frame #401

yutannihilation opened this issue Oct 31, 2017 · 1 comment
Labels
feature a feature request or enhancement

Comments

@yutannihilation
Copy link
Member

At first, I thought the behaviour of flatten_dfr() reported on #374 was a bug but it's not. As a data.frame is basically a list, flatten() transforms a list of data.frames to a list:

reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-10-31

library(purrr)
x <- data.frame(a = 1:2, b= 10:11)
flatten(list(x, x))
#> $a
#> [1] 1 2
#> 
#> $b
#> [1] 10 11
#> 
#> $a
#> [1] 1 2
#> 
#> $b
#> [1] 10 11

and then converts this to a data.frame by bind_rows(). So, theoretically, there is nothing weird that the columns will be overwritten by the ones of the same name.

flatten_dfr(list(x, x))
#> # A tibble: 2 x 2
#>       a     b
#>   <int> <int>
#> 1     1    10
#> 2     2    11

That said, I feel this is counter-intuitive; considering that a list of multiple vectors is flattened into one concatenated vector, we naturally expect a list of data.frames will be a data.frame whose content is a concatenation of the rows in the data.frames:

#> # A tibble: 4 x 2
#>       a     b
#>   <int> <int>
#> 1     1    10
#> 2     2    11
#> 3     1    10
#> 4     2    11

Is it possible to use rowwise semantics for data.frame? (If not, I think flatten_dfr() and flatten_dfc() should be removed to avoid confusion. In most cases, bind_rows() and bind_cols() are the ones that is needed actually.)

@hadley hadley added the feature a feature request or enhancement label Feb 5, 2018
@hadley
Copy link
Member

hadley commented Feb 5, 2018

Duplicate of #374

@hadley hadley marked this as a duplicate of #374 Feb 5, 2018
@hadley hadley closed this as completed Feb 5, 2018
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

2 participants