我正在尝试与dplyr::mutate()
结合使用purrr::map()
来创建一个“食谱”对象recipes::recipe()
。
如果我在tibble上下文中执行此操作,则效果很好:
library(rsample)
library(recipe)
iris_split <- initial_split(iris, prop = 0.6)
data_set_training <- training(iris_split)
recipe_standalone <- recipe(x = data_set_training, Species ~ .) # works
相比之下:
library(tibble)
library(dplyr)
library(purrr)
library(tidyr)
tibble(subset_training = data_set_training) %>%
nest(subset_training = subset_training) %>%
mutate(iris_recipe = map(.x = subset_training, .f = ~recipe(x = .x, Species ~ .))) # doesn't work
错误:
mutate()
列有问题iris_recipe
。
我iris_recipe = map(.x = subset_training, .f = ~recipe(x = .x, Species ~ .))
。
未找到 x 对象“物种”
如何使用map()
创建包含“recipe”对象的新列表列?
所需的输出
为了演示,我想得到这个:
desired_output <-
tibble(subset_training = list(data_set_training),
iris_recipe = list(recipe_standalone))
## # A tibble: 1 x 2
## subset_training iris_recipe
## <list> <list>
## 1 <df [90 x 5]> <recipe>