convert a "wide" map into a "long" one

melt_map(df, id, measure, sep_pattern = NA)

Arguments

df

tibble. rows containing NA in any of following variables are removed.

id

string. name of a character variable in df, its elements must be unique and can only contain one value each

measure

string. name of a character variable in df, its elements needn't to be unique and contain multiple values (we use stringr::str_split() to sperate them by sep_pattern)

sep_pattern

string. see measure, note that it is a pattern, for example, '|' should be '\|'

Value

tibble. column names are id and measure.

See also

Other mapping: cast_map()

Examples

tibble::tribble(
    ~symbol, ~id, ~foobar,
    'A|B', '1', 'foo',
    'C', '2', 'bar',
    'D', '2', 'foobar'
) %>% melt_map('id', 'symbol', '\\|')
#> # A tibble: 4 × 2
#>   id    symbol
#>   <chr> <chr> 
#> 1 1     A     
#> 2 1     B     
#> 3 2     C     
#> 4 2     D