knitr::opts_chunk$set(echo = TRUE)
options(width = 70) #Width of the html output
# Data import
mydata <- read.table("./Reading csv data.csv", #The name of the file which the data are to be read from
header = TRUE, #A logical value indicating whether the file contains the names of the variables as its first line
sep = ";", #The field separator character
dec = ",") #The character used in the file for decimal points
#Showing first 6 rows of dataframe
head(mydata)
## ID Height Weight
## 1 1 179.0 70
## 2 2 178.0 68
## 3 3 174.0 64
## 4 4 174.0 63
## 5 5 173.5 61
## 6 6 173.0 60
Description of variables:
#Ordering units by height
head(mydata[order(mydata$Height), ])
## ID Height Weight
## 20 20 166 55
## 8 8 168 57
## 9 9 168 56
## 7 7 170 57
## 18 18 170 58
## 19 19 170 57
mydata$Height_m <- mydata$Height / 100 #Calculating new variable Height in meters and saving it to the existing data frame
mydata$BMI <- mydata$Weight / mydata$Height_m^2 #Calculating new variable Body mass index
head(mydata)
## ID Height Weight Height_m BMI
## 1 1 179.0 70 1.790 21.84701
## 2 2 178.0 68 1.780 21.46194
## 3 3 174.0 64 1.740 21.13886
## 4 4 174.0 63 1.740 20.80856
## 5 5 173.5 61 1.735 20.26427
## 6 6 173.0 60 1.730 20.04745
summary(mydata$BMI) #Descriptive statistics of variable BMI
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 19.72 20.06 21.10 21.20 22.35 23.25
boxplot(mydata$BMI) #Showing boxplot for variable BMI