bw= read.csv("C:\\Users\\nx2li\\Desktop\\R - Nhat\\DỮ LIỆU THỰC HÀNH (TS Thạch gửi)\\birthwt.csv")
dim(bw)
## [1] 189 11
head(bw)
## id low age lwt race smoke ptl ht ui ftv bwt
## 1 85 0 19 182 2 0 0 0 1 0 2523
## 2 86 0 33 155 3 0 0 0 0 3 2551
## 3 87 0 20 105 1 1 0 0 0 1 2557
## 4 88 0 21 108 1 1 0 0 1 2 2594
## 5 89 0 18 107 1 1 0 0 1 0 2600
## 6 91 0 21 124 3 0 0 0 0 0 2622
prombt: cho biết lệnh R để kiểm 10 dòng cuối của dữ liệu bw
tail(bw,10)
## id low age lwt race smoke ptl ht ui ftv bwt
## 180 71 1 17 120 2 0 0 0 0 2 2438
## 181 75 1 26 154 3 0 1 1 0 1 2442
## 182 76 1 20 105 3 0 0 0 0 3 2450
## 183 77 1 26 190 1 1 0 0 0 0 2466
## 184 78 1 14 101 3 1 1 0 0 0 2466
## 185 79 1 28 95 1 1 0 0 0 2 2466
## 186 81 1 14 100 3 0 0 0 0 2 2495
## 187 82 1 23 94 3 1 0 0 0 0 2495
## 188 83 1 17 142 2 0 0 1 0 0 2495
## 189 84 1 21 130 1 1 0 1 0 3 2495
bw$mwt= bw$lwt *0.45
lệnh 1
bw$ethnicity[bw$race==1]="white"
bw$ethnicity[bw$race==2]="black"
bw$ethnicity[bw$race==3]="other"
lệnh 2
bw$ethnicity3 = factor(bw$race,
levels=c(1,2,3),
labels=c("white","black","other"))
lệnh 3
bw$ethnicity2 <- ifelse(bw$race == 1, "white",
ifelse(bw$race == 2, "black", "other"))
###5.3: tạo tập tin bw1
bw1=bw[, c("id","low","bwt")]
bw3=subset(bw,low==1)
bw4=subset(bw, low==1 & smoke==1 & ethnicity=="white")