Making good column names R

杀马特。学长 韩版系。学妹 提交于 2019-12-10 14:47:39

问题


I read a table from Microsoft Access using RODBC. Some of the variables had a name with a space in it.

R has no problem with it but I do. I cannot find out how to specify the space

names(alltime)
 [1] "ID"            "LVL7"          "Ref Pv No"     "Ref Pv Name"   "DOS"           "Pt Last Name"  "Pt First Name" "MRN"           "CPT"           "CPT Desc"      "DxCd1"         "DxCd2"         "DxCd3"         "DxCd4"        
[15] "DOE"    

But what do I do if I want to do something such as this

> alltime[grep("MIDDLE EAR EXPLORE",alltime$CPT Desc,]
Error: unexpected symbol in "alltime[grep("MIDDLE EAR EXPLORE",alltime$CPT Desc"

回答1:


Also see make.names




回答2:


You can quote the column name, e.g.

alltime$'CPT Desc'


来源:https://stackoverflow.com/questions/1395158/making-good-column-names-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!