mydata <- data.frame("ID" = c(1, 2, 3, 4, 5),
"Height" = c(123, 152, 253, 531, 531),
"Weight" = c(30, 50, 20, 60, 70))
mean(mydata$Height) #Calculation of mean - height
## [1] 318
On average everyone in the sample has 318cm
summary(mydata[ , -1]) # bitno! [(ovde e za rows), (ovde e za columns)] !
## Height Weight
## Min. :123 Min. :20
## 1st Qu.:152 1st Qu.:30
## Median :253 Median :50
## Mean :318 Mean :46
## 3rd Qu.:531 3rd Qu.:60
## Max. :531 Max. :70
mydata$Gender <- c("F", "F", "M", "M", "M") # creating a variable
Calculate a new variable, called BMI
mydata$BMI <- round(mydata$Height / (mydata$Height/100)^2, 1)