Skip to content

Instantly share code, notes, and snippets.

@dsparks
Created October 16, 2014 17:25
Show Gist options
  • Save dsparks/9a9d80ec168ff5eab45c to your computer and use it in GitHub Desktop.
Save dsparks/9a9d80ec168ff5eab45c to your computer and use it in GitHub Desktop.
Odd insistence on ungroup()
library(dplyr)
library(tidyr)
myDF <- data.frame(A = sample(LETTERS[1:4], 100, replace = TRUE),
B = sample(letters[5:9], 100, replace = TRUE),
C = rnorm(100))
summaryDF <- myDF %>% group_by(A, B) %>% dplyr::summarise(meanC = mean(C))
summaryDF %>% spread(B, meanC) # Error: index out of bounds
summaryDF %>% ungroup() %>% spread(B, meanC) # Works
@petbadger
Copy link

The above code actually does work now (at least for me) I find some dplyr nuisances are actually caused by the data being a Tibble. Maybe that was the problem 4 years ago...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment