求解线性方程式吗?

时间:2019-04-30 11:04:03

标签: r dplyr tibble

给出以下方程式定义:

For men: (10 x w) + (6.25 x h) - (5 x a) + 5
For women:(10 x w) + (6.25 x h) - (5 x a) - 161

位置:

w = weight in kg (1 pound = 0.45359237 kilograms)
h = height in cm (1 inch = 2.54 centimeters)
a = age (in years)

活动因子类别定义:

1.2 if sedentary, little or no exercise and desk job
1.375 if lightly Active, light exercise, or sports 1-3 days a week
1.55 if moderately active, moderate exercise, or sports 3-5 days a week
1.725 if very active, hard exercise, or sports 6-7 days a week
1.9 if extremely active, hard daily exercise or sports and physical job

我正在尝试在给定N-1个变量的情况下进行逆向计算。

例如:

target_calories: 1500
gender: F
weight = 50
height = 170
What is her age?

age = (target_calories - ((10*w) + (6.25*h) + 5))/(-5)

我正在尝试将其概括,这是我到目前为止所做的:

var_table <- tibble(gender = "M", 
                      w_kg = w_kg, 
                      h_cm = h_cm,
                      age = age,
                      activity_factor = activity_factor)

  var2calc <- names(which(sapply(var_table, anyNA)))

我可以使用许多if-else语句来解决此问题,但我正在尝试使其变得高效而优雅。

我考虑过以上tibble var_table + dplyr verbs中的计算,并给出了缺失的变量值,请根据特定公式进行计算。

请告知最佳方法是什么?

0 个答案:

没有答案