Question::
What is the equivalent purrr/furrr function for apply, which takes a data-frame and row-wise feeds it to a function?
Context::
I have a data.frame of parameter combinations:
n=10
parameters <- data.frame(
lam = runif(n = n, min = .35, max = .5),
# cs = runif(n = n, min = 1.3, max = 2.5),
cs = rnorm(n = n, mean = 1.18, sd = 0.15),
af = runif(n = n, min = 1.5, max = 2.2)
)
I have a function that takes values from the parameters data.frame and produces a vector.
gradient_model <- function(parameters) {
lam <- parameters[1]
cs <- parameters[2]
af <- parameters[3]
x <- rep(0, 5)
for (i in seq(1, 5)) {
x[i + 1] <- x[i] + lam * (cs * af - x[i])
}
return(x %>% unlist())
}
Currently I'm using apply but can't find the equivalent purrr (and hence furrr for parallel) command
For every row of parameters run the recurrence function gradientModel and store the results in a data.frame
predictions <- apply(parameters, 1, gradient_model)
What is the equivalent purrr/furrr function?
pmap*()(and hencefuture_pmap*()) matches arguments by names, so you could do: