Code block:
# r 4.1, native pipe has no _ placeholder
diamonds |>
group_by(cut, color) |>
nest() |>
crossing(bla = c(0.1, 0.5, 0.6)) |>
mutate(
mod.lm = map(data, ~ lm(price ~ depth, data = .x)),
test_data = pmap(list(data, mod.lm, bla), function(.a, .b, .c) {.a |> filter(carat >= .c) |> mutate(prediction_lm = predict(object = .b))})
)
I am trying to pass params from purr::map through to filter and then mutate. I.e. I want to add a prediction to a subset of data, where nested data frame data is first filtered before being passed to predict, along with the model mod.lm in the previous mutate line (.a |> filter(carat >= .c))
The above code block gives error:
Error: Problem with
mutate()columntest_data.![]()
test_data = pmap(...). x Problem withmutate()columnprediction_lm.
prediction_lm = predict(object = .b).![]()
prediction_lmmust be size
148 or 1, not 163.
How can I create a new data frame via pmap() where I pass in args mod.lm, the data data and field bla to filter with?