You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.)
The text was updated successfully, but these errors were encountered:
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: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.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:
Is it possible to use rowwise semantics for data.frame? (If not, I think
flatten_dfr()
andflatten_dfc()
should be removed to avoid confusion. In most cases,bind_rows()
andbind_cols()
are the ones that is needed actually.)The text was updated successfully, but these errors were encountered: