EX 01

library(MASS)
ls("package:MASS")[94:103]
##  [1] "minn38"            "motors"            "muscle"           
##  [4] "mvrnorm"           "nclass.freq"       "neg.bin"          
##  [7] "negative.binomial" "negexp.SSival"     "newcomb"          
## [10] "nlschools"

#EX02

dta<-women
dta$height_centered <-with(dta,height-mean(height))
coef(lm(weight ~ height, data = dta))
## (Intercept)      height 
##   -87.51667     3.45000
coef(lm(weight ~ height_centered, data = dta))
##     (Intercept) height_centered 
##        136.7333          3.4500

平移不會改變斜率

#EX03

c(women)
## $height
##  [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## 
## $weight
##  [1] 115 117 120 123 126 129 132 135 139 142 146 150 154 159 164

兩個資料框合併成一個清單

c(as.matrix(women))
##  [1]  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72 115 117
## [18] 120 123 126 129 132 135 139 142 146 150 154 159 164

將所有資料合併成一個矩陣 #EX04

head(birthwt$race)
## [1] 2 3 1 1 1 3
y <- c("White", "Black", "Other")

用文字取代原本變項的數值