R: Un-nest Nested Text Columns

unnest_text {textshape} | R Documentation

## Un-nest Nested Text Columns

### Description

Un-nest nested text columns in a data.frame. Attempts to locate the nested text column without specifying.

### Usage

    unnest_text(dataframe, column, integer.rownames = TRUE, ...)

### Arguments

`dataframe` | A dataframe object.
`column` | Column name to search for markers/terms.
`integer.rownames` | logical. If `TRUE` then the rownames are numbered 1 through number of rows, otherwise the original row number is retained followed by a period and the element number from the list.
`...` | ignored.

### Value

Returns an un-nested data.frame.

### Examples

    dat <- DATA

    ## Add a nested/list text column
    dat$split <- lapply(dat$state, function(x) {
        unlist(strsplit(x, '(?<=[?!.])\\s+', perl = TRUE))
    })

    unnest_text(dat)
    unnest_text(dat, integer.rownames = FALSE)

    ## Add a second nested integer column
    dat$d <- lapply(dat$split, nchar)
    ## Not run:
    unnest_text(dat) # causes error, must supply column explicitly

    ## End(Not run)
    unnest_text(dat, 'split')

    ## As a data.table
    library(data.table)
    dt_dat <- data.table::as.data.table(data.table::copy(dat))
    unnest_text(dt_dat, 'split')
    ## Not run:
    unnest_text(dt_dat, 'd')

    ## End(Not run)

    ## Not run:
    ## As a tibble
    library(tibble)
    t_dat <- tibble:::as_tibble(dat)
    unnest_text(t_dat, 'split')

    ## End(Not run)

[Package textshape version 1.6.0 Index]