Вот несколько вариантов, которые могут помочь вам получить ожидаемый результат
library(dplyr)
library(purrr)
temp <- head(all_options)
1) rowwise
temp %>%
rowwise() %>%
mutate(mifflin_eq_calories = mifflin_equation(gender = gender,
w_kg = w,
h_cm = h,
age = age,
activity_type = activity))
2) pmap
temp %>% mutate(mifflin_eq_calories = pmap_dbl(
list(gender, w, h, age, activity), mifflin_equation))
3) База R mapply
mapply(mifflin_equation, temp$gender, temp$w, temp$h, temp$age, temp$activity)
4) Vectorize
ваша функция
new_fun <- Vectorize(mifflin_equation)
4a) применить, используя mutate
temp %>%
mutate(mifflin_eq_calories = new_fun(gender = gender,
w_kg = w,
h_cm = h,
age = age,
activity_type = activity))
4b) Или напрямую
new_fun(temp$gender, temp$w, temp$h, temp$age, temp$activity)
5) data.table
library(data.table)
setDT(temp)[, ans:= mifflin_equation(gender, w, h, age, activity),by = 1:nrow(temp)]