Exercise in Chapter2 of ISL.
1.将导入数据的第一列固定为rownames,fix()
快速编辑。(数据集名称为college)
rownames(college) <- college[, 1]
college <- college[, -1]
2.用pairs()
创建散点图矩阵
pairs(college[, c(1:10)])
# create a scatter matrix using the first to tenth columns in data set.
3.使用plot()
时,如果x-axis是定性变量,图会自动转换为boxplot。
4.对数据集增加新的变量,并且根据已有变量的关系赋值。
Elite <- rep ("NO", nrow(college))
#create a new vector all in logistic "NO", length equals the row length of college.
Elite[college $ Toptenperc >50] <- "YES".
#if the variable Toptenperc > 50 ,then coded as "YES".
Elite <- as.factor(Elite)
#transfer to factor.
college <- data.frame(college, Elite)
#merge Elite into college.