R/superspread_fill.R
superspread_fill.Rd
Convert single-code column(s) into "multiple choice" formats, filling data from a target column
superspread_fill(df, tcol, select_helpers = everything(), target_col)
Data frame to apply function to.
Number of columns to create
Use dplyr select helpers to apply function only to required columns.
Target column to take values from, in order to fill the new columns Leave blank to include everything
library(dplyr)
library(magrittr)
data.frame(a=c(1,2,4,5,6,7,8),b=c(244,333,434,453,123,123,435)) %>%
superspread_fill(8,"a","b")
#> a 1 2 3 4 5 6 7 8
#> 1 1 244 0 0 0 0 0 0 0
#> 2 2 0 333 0 0 0 0 0 0
#> 3 4 0 0 0 434 0 0 0 0
#> 4 5 0 0 0 0 453 0 0 0
#> 5 6 0 0 0 0 0 123 0 0
#> 6 7 0 0 0 0 0 0 123 0
#> 7 8 0 0 0 0 0 0 0 435