Returns a list of lists with each sub-list being a row of the data frame.

df_rows_to_list(x, named = TRUE)

Arguments

x

[data.frame]
Data frame.

named

[logical(1)]
Should the sub-lists be named? If TRUE the colnames(x) are used if available. Otherwise names “V1, ...,VX” are used where X equals ncol(x). Default is TRUE.

Value

List of (named) lists.

See also

Other data frame helpers: df_add_category(), df_add_constant_columns(), df_explode(), df_split_col()

Examples

x = data.frame(x = 1:3, y = letters[3:5]) df_rows_to_list(x)
#> [[1]] #> [[1]]$x #> [1] 1 #> #> [[1]]$y #> [1] "c" #> #> #> [[2]] #> [[2]]$x #> [1] 2 #> #> [[2]]$y #> [1] "d" #> #> #> [[3]] #> [[3]]$x #> [1] 3 #> #> [[3]]$y #> [1] "e" #> #>
df_rows_to_list(x, named = FALSE)
#> [[1]] #> [[1]][[1]] #> [1] 1 #> #> [[1]][[2]] #> [1] "c" #> #> #> [[2]] #> [[2]][[1]] #> [1] 2 #> #> [[2]][[2]] #> [1] "d" #> #> #> [[3]] #> [[3]][[1]] #> [1] 3 #> #> [[3]][[2]] #> [1] "e" #> #>
df_rows_to_list(unname(x), named = FALSE)
#> [[1]] #> [[1]][[1]] #> [1] 1 #> #> [[1]][[2]] #> [1] "c" #> #> #> [[2]] #> [[2]][[1]] #> [1] 2 #> #> [[2]][[2]] #> [1] "d" #> #> #> [[3]] #> [[3]][[1]] #> [1] 3 #> #> [[3]][[2]] #> [1] "e" #> #>