You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a feature suggestion inspired by how the fill argument was used in spread.
Currently, in pivot_wider, when you want to "fill" non-existing values, you need to provide a named list for each original column (what fill value should be used). It is common to use the same fill value for all column (and sometimes, its just a single column we're widening).
I suggest that if the user provides a value instead of a named list, the function will apply this value on all cases (as if it was specified with a named list containing all the value columns).
By example:
to_wider <- tribble(
~id, ~names_from_here, ~values_from_here,
1, "col_a", 10,
1, "col_b", 20,
2, "col_b", 30
)
# this works fine:
pivot_wider(to_wider,
names_from = names_from_here, values_from = values_from_here,
values_fill = list(values_from_here = -99))
# A tibble: 2 x 3
# id col_a col_b
# <dbl> <dbl> <dbl>
#1 1 10 20
#2 2 -99 30
# this yields an error (but I expected it to work and yield the same output as the previous call)
pivot_wider(to_wider,
names_from = names_from_here, values_from = values_from_here,
values_fill = -99)
# Error in values_fill[[value]] : subscript out of bounds
This suggestion slightly resembles issue #739 (which suggests a similar behavior for the values_fn argument).
The text was updated successfully, but these errors were encountered:
hadley
changed the title
In pivot_wider, when the values_fill is provided as a value instead of a named list, apply it on all values_from columns
Allow single values_fill in pivot_wider()
Nov 24, 2019
This is a feature suggestion inspired by how the
fill
argument was used inspread
.Currently, in
pivot_wider
, when you want to "fill" non-existing values, you need to provide a named list for each original column (what fill value should be used). It is common to use the same fill value for all column (and sometimes, its just a single column we're widening).I suggest that if the user provides a value instead of a named list, the function will apply this value on all cases (as if it was specified with a named list containing all the value columns).
By example:
This suggestion slightly resembles issue #739 (which suggests a similar behavior for the
values_fn
argument).The text was updated successfully, but these errors were encountered: