How to fix spaces in column names of a data.frame (remove spaces, inject dots)?

后端 未结 12 1221
我寻月下人不归
我寻月下人不归 2020-12-07 15:28

After importing a file, I always try try to remove spaces from the column names to make referral to column names easier.

Is there a better way to do this other then

12条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 16:10

    Assign the names like this. This works best. It replaces all white spaces in the name with underscore.

    names(ctm2)<-gsub("\\s","_",names(ctm2))

提交回复
热议问题