본문 바로가기
R

(R) The way to name the unnamed first column, change the name of variables.

by jangpiano 2020. 8. 19.
반응형

<The way to name the unnamed first column>


> View(USJudgeRatings)


> USJR<-cbind(rownames(USJudgeRatings),USJudgeRatings)

> View(USJR)



> rownames(USJR)<-NULL

> View(USJR)




> colnames(USJR)[1]<-"NAME"

> View(USJR)



> names(USJR)

 [1] "NAME" "INTG" "DMNR" "DILG" "CFMG" "DECI" "PREP" "FAMI" "ORAL"

[10] "WRIT" "PHYS" "RTEN" NA    


<Change the name of variables>


<basic way>


> USJR_SUBSET<-USJR[1:3]


> names(USJR_SUBSET)

[1] "NAME" "CONT" "INTG"


> names(USJR_SUBSET)<-c("NAMES","CONTACTS","INTEGRITY")

> names(USJR_SUBSET)

[1] "NAMES"  "CONTACTS" "INTEGRITY" 

> View(USJR_SUBSET)


<Change the name of variables - using rename() in dplyr>


>library(dplyr)


> USJR_SUBSET2<-rename(USJR_SUBSET, NAMES=NAMES,THENUMBEROF_CONTACTS=CONTACTS,JUDICAL_INTEGRITY=INTEGRITY)

> View(USJR_SUBSET2)



> names(USJR_SUBSET2)

[1] "NAMES"                "THENUMBEROF_CONTACTS" "JUDICAL_INTEGRITY"  






반응형