rename_list: Rename Data Nested within a List

Description Usage Arguments Value Examples

View source: R/rename_list.R

Description

Loops through the elements of a list and adds a name_id column to data.frames corresponding to the provided names.

Usage

1
rename_list(my_list, names = NULL)

Arguments

my_list

a list; list elements may or may not have names

names

character vector; the names of the elements of the list, if the list is unnamed

Value

a list

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# example 1
paths <- list.files(directory)
files <- lapply(paths, fread)
rename_list(list = files, names = paths)

# example 2
l <- purrr::rerun(5, x = list(a = head(mtcars), b = head(iris), c = list(o = 1, p = list(q = head(airquality), u = 1:10))), y = head(mtcars))
rename_list(l, names = paste0("id", 1:5))

names(l) <- paste0("id", 1:5)
rename_list(l)

jennguyen1/jn.general documentation built on March 20, 2018, 4:26 a.m.