Skip to content

cbind gives unexpected result on group_by objects when the grouping column is removed #2102

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

Closed
billdenney opened this issue Aug 31, 2016 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@billdenney
Copy link
Contributor

When I create a group_by object based on a column or set of columns, then I perform cbind with that group_by object, the result is a matrix of lists rather than the expected object (either a tbl_df or a data.frame):

> x <- tbl_df(data=data.frame(a=rep(1:3, each=3), b=1:9, c=10:18))
> cbind(x[,"a", drop=FALSE], x[,c("b", "c"), drop=FALSE])
  a b  c
1 1 1 10
2 1 2 11
3 1 3 12
4 2 4 13
5 2 5 14
6 2 6 15
7 3 7 16
8 3 8 17
9 3 9 18
> 
> x <- group_by(x, a)
> cbind(x[,"a", drop=FALSE], x[,c("b", "c"), drop=FALSE])
  [,1]      [,2]     
b Integer,9 Integer,9
c Integer,9 Integer,9
> class(cbind(x[,"a", drop=FALSE], x[,c("b", "c"), drop=FALSE]))
[1] "matrix"
> 
@krlmlr
Copy link
Member

krlmlr commented Nov 7, 2016

Thanks, confirmed. Would you like to contribute a testthat test?

Similar issue with rbind: #2138.

@billdenney
Copy link
Contributor Author

I think that the testthat test would be what I gave above:

x <- tbl_df(data=data.frame(a=rep(1:3, each=3), b=1:9, c=10:18))
expect_equal(cbind(x[,"a", drop=FALSE], x[,c("b", "c"), drop=FALSE]), x)

@krlmlr krlmlr added bug an unexpected problem or unintended behavior data frame labels Dec 15, 2016
@krlmlr
Copy link
Member

krlmlr commented Feb 10, 2017

Keeping #2138 as canonical issue.

@krlmlr krlmlr closed this as completed Feb 10, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants