R Lang

# R Code to Calculate BMI3 min read

### R program to calculate Body Mass Index (BMI)

The Body Mass Index (BMI) is a quick way to assess your body size simply with your weight and height, regardless of your gender. Quickly calculate your BMI and find out which category you fall into.

The Body Mass Index (BMI) is the only index validated by the World Health Organization to assess an individual’s build and therefore health risks. The BMI makes it possible to determine whether one is the situation of thinness, overweight or obesity for example.

In this program we will calculate BMI. Body mass index (BMI) is a measure of body fat based on height and weight that applies to adult men and women.

### R Code: Write a program that calculates and displays a person’s body mass index in R Lang

bmi.r file

The first two lines of code create variables called `user.height` and `user.weight` and assign them values of 69 and 150, respectively. The next two lines convert these variables to double precision floating point numbers.

The fifth line calculates the BMI of the user by dividing their weight by their height squared, and then multiplying the result by a conversion factor of 703. This equation is one way of calculating BMI, but it is important to note that there are other ways to calculate BMI and some variations in the specific conversion factor used.

After calculating the BMI, the code prints it to the console. It then enters a series of `if` statements which check the value of the BMI and print a message indicating whether the person is underweight, normal weight, overweight, or obese.

### Take inputs from user

bmi2.r file

Output:

The first two lines of code read in the user’s height and weight from the console and store them in variables called `user.height` and `user.weight`, respectively. The next two lines convert these variables to double precision floating point numbers.
After calculating the BMI, the code prints it to the console. It then enters a series of `if` statements which check the value of the BMI and print a message indicating whether the person is underweight, normal weight, overweight, or obese.