文章目录
示例数据:
MASS
包中的
birthwt
数据集。
预处理
- 将分类变量因子化,具体参考这里
- 为每个变量设置标签:语法为
attr(数据框名,"var.labels")<-c(按变量顺序排列的标签名)
> attr(birthwt,"var.labels")<-c("low birth weight","mother's age(yr)","mother's weight(lbs)","mother's race","smoking status","number of premature births","history of HTN","uterine irritability","number of physician visits","birth weight(g)")
> des(birthwt) # 该函数位于epiDisplay包中
No. of observations = 189
Variable Class Description
1 low factor low birth weight
2 age integer mother's age(yr)
3 lwt integer mother's weight(lbs)
4 race factor mother's race
5 smoke factor smoking status
6 ptl integer number of premature births
7 ht factor history of HTN
8 ui factor uterine irritability
9 ftv integer number of physician visits
10 bwt integer birth weight(g)
<