How to keep columns labels when numeric convert to character

Posted by stata on Stack Overflow See other posts from Stack Overflow or by stata
Published on 2014-05-27T03:22:38Z Indexed on 2014/05/27 3:24 UTC
Read the original article Hit count: 193

Filed under:
a<- data.frame(sex=c(1,1,2,2,1,1),bq=factor(c(1,2,1,2,2,2)))
library(Hmisc)
label(a$sex)<-"gender"
label(a$bq)<-"xxx"
str(a) 

b<-data.frame(lapply(a, as.character), stringsAsFactors=FALSE)
str(b)

When I covert dataframe a columns to character,the columns labels disappeared.My dataframe have many columns.Here as an example only two columns. How to keep columns labels when numeric convert to character? Thank you!

© Stack Overflow or respective owner

Related posts about r