R: Tidy a List of Named Dataframes or Named Vectors or Vectors

tidy_list {textshape} | R Documentation

## Tidy a List of Named Dataframes or Named Vectors or Vectors

### Description

`rbind` a named `list` of `data.frame`s or `vector`s to output a single `data.frame` with the `names` from the `list` as an `id` column.

### Usage

    tidy_list(x, id.name = "id", content.name = "content",
      content.attribute.name = "attribute", ...)

### Arguments

`x` | A named `list` of `data.frame`s or `vector`.
`id.name` | The name to use for the column created from the `list`.
`content.name` | The name to use for the column created from the `list` of `vector`s (only used if `x` is `vector`).
`content.attribute.name` | The name to use for the column created from the `list` of names given to the `vector`s (only used if `x` is named `vector`).
`...` | Ignored.

### Value

Returns a `data.table` with the `names` from the `list` as an `id` column.

### Examples

    tidy_list(list(p=1:500, r=letters))
    tidy_list(list(p=mtcars, r=mtcars, z=mtcars, d=mtcars))

    x <- list(
        a = setNames(c(1:4), LETTERS[1:4]),
        b = setNames(c(7:9), LETTERS[7:9]),
        c = setNames(c(10:15), LETTERS[10:15]),
        d = c(x=4, y=6, 4),
        e = setNames(1:10, sample(state.abb, 10, TRUE)),
        f = setNames(1:10, sample(month.abb, 10, TRUE))
    )

    tidy_list(x)

    ## Not run:
    ## 2015 Vice-Presidential Debates Example
    if (!require("pacman")) install.packages("pacman")
    pacman::p_load(rvest, magrittr, xml2)

    debates <- c(
        wisconsin = "110908",
        boulder = "110906",
        california = "110756",
        ohio = "110489"
    )

    lapply(debates, function(x){
        paste0("http://www.presidency.ucsb.edu/ws/index.php?pid=", x) %>%
            xml2::read_html() %>%
            rvest::html_nodes("p") %>%
            rvest::html_text() %>%
            textshape::split_index(grep("^[A-Z]+:", .)) %>%
            textshape::combine() %>%
            textshape::split_transcript() %>%
            textshape::split_sentence()
    }) %>%
        textshape::tidy_list("location")

    ## End(Not run)

[Package textshape version 1.6.0 Index]