df2list: Row-wise conversion of a data frame to a list

Description Usage Arguments Value Author(s) See Also Examples

View source: R/df2list.R

Description

Convert a data frame to a list, where each element of the output list consists of a named list (or a named vector) containing a single row of the data frame.

Usage

1
df2list(df, out.type = c("list", "data.frame", "vector"))

Arguments

df

A data frame

out.type

Character string uniquely identifying 'list', 'data.frame', or 'vector'. If 'list', then each row of the data frame is output as a list. If 'data.frame', then each row of the data frame is output as a 1-row data frame. If 'vector', then each row of the data frame is output as a named vector. However, for 'vector,' each column of the data set must be the same type. Defaults to 'list'.

Value

A list where each element consists of a named list, single-row data frame, or a named vector, containing a single row of the original data frame.

Author(s)

Landon Sego

See Also

list2df, as.list

Examples

1
2
3
4
5
d <- data.frame(a = 1:3, b = letters[1:3])
df2list(d)

d1 <- data.frame(a = 1:3, b = 7:9)
df2list(d1, out.type = "v")

pnnl/Smisc documentation built on Oct. 18, 2020, 6:18 p.m.