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
Is it possible to make the fill argument in complete work the same way as the value_fill argument in pivot_wider, i.e., if only a single value is passed, assume this applies to all variables? This would make it easier to deal with many variables, without having to specifically write a list with every single variable and the value I want to fill in with.
Apologies if I have missed a way to actually do this. In any case, consistency across the two functions could be useful.
library(dplyr)
#> #> Attaching package: 'dplyr'#> The following objects are masked from 'package:stats':#> #> filter, lag#> The following objects are masked from 'package:base':#> #> intersect, setdiff, setequal, union
library(tidyr) #1.1.3# with values_fill in pivot_wider, if I provide a single value, default is to assume propagation to all variables
pivot_wider(fish_encounters, names_from=station, values_from=seen, values_fill=2)
#> # A tibble: 19 x 12#> fish Release I80_1 Lisbon Rstr Base_TD BCE BCW BCE2 BCW2 MAE MAW#> <fct> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>#> 1 4842 1 1 1 1 1 1 1 1 1 1 1#> 2 4843 1 1 1 1 1 1 1 1 1 1 1#> 3 4844 1 1 1 1 1 1 1 1 1 1 1#> 4 4845 1 1 1 1 1 2 2 2 2 2 2#> 5 4847 1 1 1 2 2 2 2 2 2 2 2#> 6 4848 1 1 1 1 2 2 2 2 2 2 2#> 7 4849 1 1 2 2 2 2 2 2 2 2 2#> 8 4850 1 1 2 1 1 1 1 2 2 2 2#> 9 4851 1 1 2 2 2 2 2 2 2 2 2#> 10 4854 1 1 2 2 2 2 2 2 2 2 2#> 11 4855 1 1 1 1 1 2 2 2 2 2 2#> 12 4857 1 1 1 1 1 1 1 1 1 2 2#> 13 4858 1 1 1 1 1 1 1 1 1 1 1#> 14 4859 1 1 1 1 1 2 2 2 2 2 2#> 15 4861 1 1 1 1 1 1 1 1 1 1 1#> 16 4862 1 1 1 1 1 1 1 1 1 2 2#> 17 4863 1 1 2 2 2 2 2 2 2 2 2#> 18 4864 1 1 2 2 2 2 2 2 2 2 2#> 19 4865 1 1 1 2 2 2 2 2 2 2 2# fill argument in complete does not work the same way# error
complete(fish_encounters, station, fish, fill=2)
#> Error in replace_na.data.frame(full, replace = fill): is_list(replace) is not TRUE# appears to work, but doesn't..
complete(fish_encounters, station, fish, fill=list(2)) %>% filter(seen==2)
#> # A tibble: 0 x 3#> # … with 3 variables: station <fct>, fish <fct>, seen <int># ..they're NAs
complete(fish_encounters, station, fish, fill=list(2)) %>% filter(is.na(seen))
#> # A tibble: 95 x 3#> station fish seen#> <fct> <fct> <int>#> 1 Lisbon 4849 NA#> 2 Lisbon 4850 NA#> 3 Lisbon 4851 NA#> 4 Lisbon 4854 NA#> 5 Lisbon 4863 NA#> 6 Lisbon 4864 NA#> 7 Rstr 4847 NA#> 8 Rstr 4849 NA#> 9 Rstr 4851 NA#> 10 Rstr 4854 NA#> # … with 85 more rows# works if i name the variable individually, but cumbersome when I have many variables
complete(fish_encounters, station, fish, fill=list(seen=2)) %>% filter(seen==2)
#> # A tibble: 95 x 3#> station fish seen#> <fct> <fct> <dbl>#> 1 Lisbon 4849 2#> 2 Lisbon 4850 2#> 3 Lisbon 4851 2#> 4 Lisbon 4854 2#> 5 Lisbon 4863 2#> 6 Lisbon 4864 2#> 7 Rstr 4847 2#> 8 Rstr 4849 2#> 9 Rstr 4851 2#> 10 Rstr 4854 2#> # … with 85 more rows
Is it possible to make the
fill
argument incomplete
work the same way as thevalue_fill
argument inpivot_wider
, i.e., if only a single value is passed, assume this applies to all variables? This would make it easier to deal with many variables, without having to specifically write a list with every single variable and the value I want to fill in with.Apologies if I have missed a way to actually do this. In any case, consistency across the two functions could be useful.
Created on 2021-03-24 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: