#Bài thực hành 1
#Việc 1: Cài đặt R và RStudio
https://cran.r-project.org/mirrors.html https://www.rstudio.com/products/rstudio/download
#Việc 2: Cài đặt các gói lệnh (packages)
install.packages(c(“lessR”, “table1”, “compareGroups”, “simpleboot”, “boot”, “GGally”, “gapminder”, “ggfortify”, “BMA”, “ggplot2”, “gridExtra”), dependencies = T)
#Việc 3: Đọc dữ liệu vào R
ob=read.csv(“C:\Users\Admin\Downloads\Obesity data.csv”)
Tìm đường dẫn với “file.choose()” a=file.choose()
#Việc 4: Thông tin về dữ liệu ob
##4.1: Có bao nhiêu biến số và quan sát
dim(ob)
##4.2: Liệt kê 6 quan sát đầu tiên
head(ob)
##4.3: Liệt kê 6 quan sát cuối cùng
tail(ob)
##4.4: Tóm tắt dữ liệu
summary(ob)
#Việc 5: Biên tập dữ liệu ##5.1: Mã hoá biến gender
ob\(sex[ob\)gender==“M”]=0
ob\(sex[ob\)gender==“F”]=1
table(ob\(sex,ob\)gender)
head(ob)
##5.2: Mã hoá biến BMI
ob\(obese[ob\)bmi<18.5]=“underweight”
ob\(obese[ob\)bmi>=18.5&ob$bmi<25.0]=“Normal”
ob\(obese[ob\)bmi>=25.0&ob$bmi<30.0]=“Overweight”
ob\(obese[ob\)bmi>=30.0]=“Obese”
##5.3: Tạo biến số mới
ob\(lean.kg = ob\)lean/1000
ob\(fat.kg = ob\)fat/1000
##5.4: Tạo 1 tập dữ liệu “men.overweight”
men.overweight=subset(ob,gender==“M”&bmi>= 25)
dim(men.overweight)
##5.5: Tạo tập dữ liệu “Demo”
Demo=subset(ob,select=c(id,age,gender,weight,height,pcfat))
dim(Demo)
head(Demo)
Demo.2=ob[,c(“id”,“age”,“gender”,“weight”,“height”,“pcfat”)]
head(Demo.2)
dim(Demo.2)