tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.75k stars 2.12k forks source link

Suppress "Column `...` must be length 1 (a summary value), not ..." #4418

Closed deliciouslytyped closed 5 years ago

deliciouslytyped commented 5 years ago

Would it be possible to add a feature for suppressing the error in the title for summarise?

Maybe I just haven't figured out the appropriate part of dplyr to use. My use case would be aggregating values in a data structure like a vector so that I can inspect them with R properly later - as opposed to using a hack like making a comma separated string.

batpigandme commented 5 years ago

Could you please turn this into a self-contained reprex (short for minimal reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page.

You can install reprex by running (you may already have it, though, if you have the tidyverse package installed):

install.packages("reprex")

Thanks

deliciouslytyped commented 5 years ago

I'll try out this reprex thing in a bit. Here's a quick reproduction I threw together by hand:

library(dplyr)
library(ggplot2)
mpg %>% group_by(model) %>% summarise(year=as.vector(year))

results in

Error in summarise_impl(.data, dots) : 
  Column `year` must be length 1 (a summary value), not 6

Edit: the goal would be to have values something like c(1999, 2000, ...) in each cell of the year column

krlmlr commented 5 years ago

summary() really requires a scalar for each group. Are you looking for nest(-model) ?

library(tidyverse)
mpg %>%
  nest(-model)
#> # A tibble: 38 x 2
#>    model              data              
#>    <chr>              <list>            
#>  1 a4                 <tibble [7 × 10]> 
#>  2 a4 quattro         <tibble [8 × 10]> 
#>  3 a6 quattro         <tibble [3 × 10]> 
#>  4 c1500 suburban 2wd <tibble [5 × 10]> 
#>  5 corvette           <tibble [5 × 10]> 
#>  6 k1500 tahoe 4wd    <tibble [4 × 10]> 
#>  7 malibu             <tibble [5 × 10]> 
#>  8 caravan 2wd        <tibble [11 × 10]>
#>  9 dakota pickup 4wd  <tibble [9 × 10]> 
#> 10 durango 4wd        <tibble [7 × 10]> 
#> # … with 28 more rows

Created on 2019-06-12 by the reprex package (v0.3.0)

Closing, because this isn't really a problem with dplyr. This sort of question is a better fit for https://community.rstudio.com. Do you mind following up there?

lock[bot] commented 4 years ago

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/