How to calculate BMI in Rstudio

(Last Updated On: July 12, 2023)

How to Calculate BMI in RStudio will never be any rocket science after you read this article. If you’ve read already anything about body mass index (BMI), it was probably something like “If your BMI indicates that you’re overweight, avoid consuming too many calories from sugar and fats.” Or something similar to that.

How to calculate BMI in Rstudio
How to calculate BMI in Rstudio

The reason it wasn’t more explained than that is that for many of us, calculating our own BMI isn’t exactly rocket science. Think about it: What does your body weight have to do with the height or length of your body? Of course Nothing.

A person can actually be very tall but have a low BMI – the same applies to short people. But how can both of these things be true at the same time, unless we are talking about some alien or some non-human being? BMI does not take into account our height.

If you are worried about whether you are overweight or not, don’t worry and take some time to calculate your BMI using this Rstudio tutorial to learn how to calculate your BMI in R Studio.

What is BMI?

BMI stands for body mass index. It’s quick and easy to measure your risk of obesity-related health problems like heart disease, type 2 diabetes, high blood pressure, and stroke.

The formula used to calculate body mass index (BMI) is body weight divided by height squared. It shows what percentage of your body weight is fat.

People with more muscle and a higher level of fitness are more likely to have a higher BMI because muscle weighs more than fat.

How to Calculate BMI in Rstudio

BMI is simply calculated using your body weight and height. You can easily calculate your BMI using R Studio by yourself. To do so, start by creating 2 vectors for your body weight and height (in kilograms and centimeters, respectively).

If you are still struggling to calculate BMI in Rstudio, here is a easy-to-use formula that will get you there.

BMI = weight (kg) / height^2 (m^2)

You can use the body weight and height variables in R to store the person’s weight and height respectively. Then you can use the following simple code to calculate BMI:

1 - bmi <- weight / (height^2) 

There’s another function to calculate BMI, where body weight and height are the input arguments:

1 - calculate_bmi <- function(weight, height) {
2 -     bmi <- weight / (height^2)
3 -     return(bmi)
4 - } 


1 - weight <- 70
2 - height <- 1.8
3 - bmi <- calculate_bmi(weight, height)
4 - print(bmi) 

output: 21.6049382716049

What does a healthy BMI look like?

The American Heart Association (AHA) recommends that people ages 19 to 49 try to maintain a BMI between 18.5 and 24.9.

If you are between 50 and 64 years old, you should shoot between 19.9 and 29.9. If you are over 65, the ideal BMI is between 21.7 and 28.9

The World Health Organization uses a different but similar scale. People with a Body Mass Index (BMI) between the range 18.5 and 25 are at a healthy weight.

People with a BMI between 25 and 30 are considered overweight, and those with a BMI of 30 or higher are considered obese.

Also Read: How To Lose Weight Fast Safely – The Ultimate Guide

Why does BMI matter?

You may have heard the famous saying, “You can’t judge a book by its face.” The same can be said for a human’s weight.

While BMI is simple and quick way to know whether you’ve healthy weight or not, it isn’t the best indicator of your overall health.

Your BMI does not take into account your age, gender, muscle mass, bone density, lifestyle, diet, and many other factors.

There are many people who are at a healthy weight but have a high percentage of body fat. While this does not mean that such a person is unhealthy, it does mean that it is more difficult to stay at a healthy weight.

In some cases, many extremely lean peoples are at a lower risk of serious health problems.

Also Read: 7 Money Rules you didn’t learn in school

Should you trust your BMI result?

The simple answer is NO. If you want to know if you are overweight or not, BMI is an easy and good way to start. But remember that it is not 100% reliable.

Now, we understand that BMI is not a perfect measure of overall health. But what we still don’t know is how it compares to other metrics. We don’t know if there are better or worse metrics for measuring human health.

So, scientists and health researchers began to look at the health of obese people and try to find solutions to predict which ones are at higher risk.

However, the truth is we don’t know everything these days. So take your BMI results with a pinch of salt.


So, if you are concerned and wondering about your weight, don’t worry too much about your BMI results. Instead, make some changes in your daily diet to help you lose weight and improve your overall health.

BMI results can be useful for tracking changes over time and comparing your results with age and gender groups in your demographic.

Finally, remember that your BMI is not diagnostic of any kind and should only be used as a guide.

Download Videos Online: