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

spread does not work on grouped_df #43

Closed
tpapp opened this issue Oct 31, 2014 · 1 comment
Closed

spread does not work on grouped_df #43

tpapp opened this issue Oct 31, 2014 · 1 comment

Comments

@tpapp
Copy link

tpapp commented Oct 31, 2014

Apparently spread does not work on grouped_df objects. Toy example:

library(dplyr)                          # from github, 2014 Oct 31
library(tidyr)                          # from github, 2014 Oct 31

## generate data
household <- rep(1:500, times = sample(5, 500, replace = TRUE))
df <- data.frame(household = household,
                 day = sample(3, length(household), replace = TRUE))

## count day indexes for each household
df_days <- summarize(group_by(df, household, day), day_count = n())
## spread, converting to data frame -- works
spread(as.data.frame(df_days), day, day_count)
## spread without conversion -- does not work
spread(df_days, day, day_count)

where the last line fails with

Error in `[.grouped_df`(data, key_col) : 
  cannot group, grouping variables 'household' not included

Maybe I misunderstood something, but I thought grouped_df could be used like data frame.

@hadley
Copy link
Member

hadley commented Dec 3, 2014

This should be fixed in the dev version of dplyr

@hadley hadley closed this as completed Dec 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants