You can calculate Body Mass Index using a normal calculator or in any programming language. Here, you will know how to calculate BMI in R programming language or RStudio.

Let’s get started,

**Formula for BMI:**

**BMI = kg/m2** (Here kg is person’s weight in kilograms and m2 is height in metres squared)

**R code to calculate BMI:**

```
bmi <- function(weightInKg, heightInMetres){
return (weightInKg / heightInMetres ^ 2)
}
bmi(70, 1.75)
```

When you run the above code in RStudio, you will get the following output.

*22.85714*

**Code explained:**

The R code for BMI calculation is a simple function, which takes two parameters weightInKg and heightInMetres.

When you call this function, you need to pass **weight in kg** and **height in metres** and in result bmi function apply formula on parameters and return calculated bmi value.

That’s it,

Hope you find this R script to calculate BMI helpful.