Rでデータ分析 カラム名を変更する

#We always use this kind of method to rename the colnames
#But, sometime we want to only change the specific column name

names(x) <- c("a","b","c")

#let's try it
#First, I will create the data

> sex    <- c("F","F","F","M","M")
> height <- c(157,164,159,178,175)
> weight <- c(46,55,50,69,72)
> x    <- data.frame(SEX=sex, HEIGHT=height, WEIGHT=weight) 
>head(x)
  SEX HEIGHT WEIGHT
1   F    157     46
2   F    164     55
3   F    159     50
4   M    178     69
5   M    175     72

#Check the column names

> names(x)
[1] "SEX"    "HEIGHT" "WEIGHT"

#Use the polular method to change the column names

> names(x) <- c("sex","height","weight")
> names(x)
[1] "sex"    "height" "weight"

#Change only the specific column

> names(x)[2] <- "b"
> names(x)
[1] "sex"    "b"      "weight"