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

后端 未结 12 1225
我寻月下人不归
我寻月下人不归 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:06

    There is an easy way to remove spaces in column names in data.table. You will have to convert your data frame to data table.

    setnames(x=DT, old=names(DT), new=gsub(" ","",names(DT)))
    

    Country Code will be converted to CountryCode

提交回复
热议问题