Skip to content

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

Closed
@billdenney

Description

@billdenney

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"
> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions