expand_column {dfexpand}R Documentation

Expand a single column containing delimited values into multiple binary columns

Description

Expand a single column containing delimited values into multiple binary columns

Usage

expand_column(
  dataframe,
  colname = NULL,
  delimiter = ";",
  trim = TRUE,
  ignore_case = FALSE,
  colnumber = NULL
)

Arguments

dataframe

The data frame containing the column we want to expand

colname

The name of the column to split on.

delimiter

A single character to split the string on.

ignore_case

Boolean flag if you want the split values to ignore case

colnumber

You can provide the column number in the dataframe to expand, rather than the name

trim

Boolean field to trim white space when searching for unique values

Value

A list of distinct values found in the entry string

Examples

    library('dfexpand')
    myDelimiter = ";"

    # Create some fake data with duplicates
    rows = c(
        c("a;b"), c("a;b;c"), c("b;c"), c("d"), c("d")
    )

    # Add to a dataframe
    df = data.frame(rows)

    colnames(df) <- c("myvar")
    #
    # The default behavior is to trim extra whitespace from the extracted values, 
    # but not to alter or change the case of the values. So 'Alpha' is distinct from 'alpha'
    # but ' beta ' is the same as 'beta'. You can override this behavior with
    # the trim and ignore case flags.
    #
    expanded_df = expand_column(df, "myvar", myDelimiter)

[Package dfexpand version 0.0.2 Index]