Skip to contents

Combine multiple columns into one

Usage

combine(df, name = combined, columns, sep = "-")

Arguments

df

<data.frame> or <tibble>

name

new column name, unquoted, default is combined

columns

<chr> vector of columns to combine

sep

separator between combined row data, default is "-"

Value

A <data.frame> or <tibble> with combined columns

Examples

x <- fuimus:::forager_data()[-5]

x[1, 2] <- ""

x
#> # A tibble: 10 × 4
#>    claim_id payer      ins_class balance
#>    <chr>    <chr>      <chr>       <dbl>
#>  1 01       ""         Secondary   100. 
#>  2 02       "Humana"   Secondary   171. 
#>  3 03       "Anthem"   Secondary   130. 
#>  4 04       "Medicare" Primary     114. 
#>  5 05       "Medicaid" Primary     247. 
#>  6 06       "Medicaid" Primary      52.2
#>  7 07       "Anthem"   Secondary    27.0
#>  8 08       "BCBS"     Primary     137. 
#>  9 09       "Humana"   Primary     254. 
#> 10 10       "Medicaid" Primary     117. 

x |>
  combine(
    name = id_payer,
    columns = c('claim_id', 'payer'))
#> # A tibble: 10 × 3
#>    id_payer    ins_class balance
#>    <chr>       <chr>       <dbl>
#>  1 01-         Secondary   100. 
#>  2 02-Humana   Secondary   171. 
#>  3 03-Anthem   Secondary   130. 
#>  4 04-Medicare Primary     114. 
#>  5 05-Medicaid Primary     247. 
#>  6 06-Medicaid Primary      52.2
#>  7 07-Anthem   Secondary    27.0
#>  8 08-BCBS     Primary     137. 
#>  9 09-Humana   Primary     254. 
#> 10 10-Medicaid Primary     117.