d2lv {str2str} | R Documentation |
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 |
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