mydata <- data.frame("ID" = c(1, 2, 3, 4, 5),
"Height" = c(170, 172, 180, 182, 186),
"Weight" = c(60, 65, 70, 77, 82))
mean(mydata$Height) #Estimation of the arithmetic mean
## [1] 178
On average everyone in the sample has 178 cm.
summary(mydata[ , -1])
## Height Weight
## Min. :170 Min. :60.0
## 1st Qu.:172 1st Qu.:65.0
## Median :180 Median :70.0
## Mean :178 Mean :70.8
## 3rd Qu.:182 3rd Qu.:77.0
## Max. :186 Max. :82.0
mydata$Gender <- c("F", "F", "M", "M", "M")
Calculate a new variable, called BMI.
mydata$BMI <- round(mydata$Weight / (mydata$Height/100)^2, 1)