使用 data.frame()
、tibble()
或 bind_cols()
轻松将向量绑定到数据框中:
library(tidyverse)
x <- 1:5
y <- letters[1:5]
d <- tibble(x, y)
什么是将数据框转换为长度等于
ncol(d)
的列表的最有效方法?在上面的示例中,期望的输出如下:> list(x = x, y = y)
$x
[1] 1 2 3 4 5
$y
[1] "a" "b" "c" "d" "e"
一个能够完成此操作的单一函数将是有用的,例如,在将数据框传递到
pmap()
时:d %>%
break_into_list() %>% # missing function here
pmap(function(x, y) paste(x, y)) # scales to dataframe with ncol > 2
tibble
转换为list
吗?也许更好的方法是使用group_map
。这个函数期望输入tibble
。 - Marek Fiołka