Skip to content

cbind'ing grouped df and df gives a matrix? #2475

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
hongooi73 opened this issue Feb 27, 2017 · 3 comments
Closed

cbind'ing grouped df and df gives a matrix? #2475

hongooi73 opened this issue Feb 27, 2017 · 3 comments

Comments

@hongooi73
Copy link

hongooi73 commented Feb 27, 2017

This is... odd behaviour to say the least.

grp_df <- data_frame(x1 = 1:10, x2 = 1:10) %>% group_by(x1)
y_df <- data_frame(y = 1:10)

foo <- cbind(grp_df, y_df)

foo
#   grp_df               
#x1 Integer,10 Integer,10
#x2 Integer,10 Integer,10

foo[[1, 1]]
# [1] 1 2 3 4 5 6 7 8 9 10

This is with dplyr 0.5.0.9000, built on 24-Jan-2017.

@hadley
Copy link
Member

hadley commented Feb 27, 2017

Duplicate of #2138. As far as I can tell, dplyr already provides the correct methods, but rbind()/cbind() don't call them because it uses a special dispatch mechanism that doesn't work for data frame subclasses.

@hadley hadley closed this as completed Feb 27, 2017
@hongooi73
Copy link
Author

I just rebuilt dplyr, and the problem is still there. Is there any solution besides just calling cbind.data.frame directly?

@hadley
Copy link
Member

hadley commented Feb 27, 2017

Yes, call bind_cols()

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants