More likely the other way around! The error message implies that your tibble is already grouped, most likely by the row variable, since the group size is 1. Try inserting an ungroup() in the pipeline:
library(tidyverse)
x <- tribble(
~row, ~`2017.2`, ~`2017.3`, ~`2017.4`, ~`2018.1`,
1, 0, 2, 3, 4,
2, 0, 0, 1, 0,
3, 0, 0, 0, 9,
4, 0, 2, 3, 4,
5, 0, 0, 1, 0
)
# Tibble is now grouped by row
x <- group_by(x, row)
# Won't work on grouped tibble
x %>% mutate(
new_col = pmap_dbl(
x,
~ 5 - min(which(c(..2, ..3, ..4, ..5) > 0))
)
)
#> Error in mutate_impl(.data, dots): Column `new_col` must be length 1 (the group size), not 5
# Add `ungroup()` to the pipeline
x %>%
ungroup() %>%
mutate(
new_col = pmap_dbl(
x,
~ 5 - min(which(c(..2, ..3, ..4, ..5) > 0))
)
)
#> # A tibble: 5 x 6
#> row `2017.2` `2017.3` `2017.4` `2018.1` new_col
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0 2 3 4 3
#> 2 2 0 0 1 0 2
#> 3 3 0 0 0 9 1
#> 4 4 0 2 3 4 3
#> 5 5 0 0 1 0 2
Created on 2018-07-11 by the reprex package (v0.2.0).
(You might also go back through your code to figure out when the tibble got grouped and removing the grouping code — grouping by row sounds like the kind of thing you might have done while trying different ways to solve this problem)