Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

d2lv

Data-Frame to List of (Atomic) Vectors


Description

d2lv converts a data.frame to a list of (atomic) vectors. This function is really only worthwhile when along = 1 since when along = 2, the function is essentially as.list.data.frame(d).

Usage

d2lv(d, along, check = TRUE)

Arguments

d

data.frame.

along

numeric vector of length 1 specifying which dimension to slice the data.frame along. If 1, then the data.frame is sliced by rows. If 2, then the data.frame is sliced by columns.

check

logical vector of length 1 specifying whether to check the structure of the input arguments. For example, check whether d is a data.frame. This argument is available to allow flexibility in whether the user values informative error messages (TRUE) vs. computational efficiency (FALSE).

Value

list of (atomic) vectors. If along = 1, then the names are the rownames of d and the vectors are rows from d. If along = 2, then the names are the colnames of d and the vector are columns from d. Note, the vectors always have the same length as nrow(d).

Examples

d2lv(mtcars, along = 1)
d2lv(mtcars, along = 2)
d2lv(CO2, along = 1) # all vectors converted to typeof character
d2lv(CO2, along = 2) # each column stays its own typeof (or class for factors)
# check = FALSE
try_expr(d2lv(mtcars, along = 3, check = FALSE)) # less informative error message
try_expr(d2lv(mtcars, along = 3, check = TRUE)) # more informative error message

str2str

Convert R Objects from One Structure to Another

v0.1.1
GPL (>= 2)
Authors
David Disabato [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.