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

More accurate implemmentation of spread() #3

Open
krlmlr opened this issue May 20, 2018 · 0 comments
Open

More accurate implemmentation of spread() #3

krlmlr opened this issue May 20, 2018 · 0 comments

Comments

@krlmlr
Copy link
Contributor

krlmlr commented May 20, 2018

The spread() verb won't work for data frames if there are duplicates in the keys. It is unfortunate that PIVOT() seems to require an aggregation function, I haven't found a way to write this operation so that no aggregates are performed (but an error is returned instead). Perhaps with a user-defined function?

Either way, FIRST_VALUE() seems to be a slightly better choice than MAX(), because it might also work for non-numeric data.

library(tidyverse)
data <- tibble(a = c(1, 1, 2), b = a, c = 4:6)
data %>%
  spread(b, c)
#> Error: Duplicate identifiers for rows (1, 2)

Created on 2018-05-20 by the reprex package (v0.2.0).

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

1 participant