> weight = c(150, 135, 210, 140)
> height = c(65, 61, 70, 65)
> gender = c("Fe","Fe","M","Fe")
> study = data.frame(weight,height,gender)
> study
weight height gender
1 150 65 Fe
2 135 61 Fe
3 210 70 M
4 140 65 Fe
关于列名,可以在构造数据框的时候指定:
> study = data.frame(w=weight,h=height,g=gender)
> study
w h g
1 150 65 Fe
2 135 61 Fe
3 210 70 M
4 140 65 Fe
> names(study) <- c("wei","hei","gen")
> study
wei hei gen
1 150 65 Fe
2 135 61 Fe
3 210 70 M
4 140 65 Fe
> row.names(study)<-c("Mary","Alice","Bob","Judy")
> study
wei hei gen
Mary 150 65 Fe
Alice 135 61 Fe
Bob 210 70 M
Judy 140 65 Fe
统计学与R读书笔记 徐俊晓