Updated: Plyr rename() not recognizing identical 'x'; Error: The following `from` values were not present in `x`:

做~自己de王妃 提交于 2019-12-18 09:45:15

问题


R 3.2.4 Plyr updated 2016-03-10

I am trying to rename columns in a large data set and running into the "The following from values were not present in x:" error.

The columns from origin export are atrocious, which is why I'm using plyr rename, but it seems that even rename is having trouble. Example trouble column is [,3] in the linked data set and is titled:

"Experimental.or.quasi.experimental..evaluation..compares.mentored.youth.to.a.comparison.or.â.œcontrolâ...group.of.non.mentored.youth..NS8"

Download link to csv here: Code below:

test<-read.csv(file="test.csv",header=TRUE)
library(plyr)
test2<-rename(test,
         c(
           "Experimental.or.quasi.experimental..evaluation..compares.mentored.youth.to.a.comparison.or.â.œcontrolâ...group.of.non.mentored.youth..NS8"="new"))

回答1:


Try using setNames instead:

library(plyr)
test2 <- rename(test, setNames( "new", names(test[3])))

names(test2)

[1] "Implementation.evaluation..examines.how.well.or.efficiently.services.were.delivered.to.participants..such.as.tracking.mentor.mentee.meetings..participation.in.trainings..etc....NS8"
[2] "Outcome.evaluation..examines.changes.in.participants.served.using.pre.post.data.collection..NS8"                                                                                     
[3] "new"                                                                                                                                                                                 
[4] "Return.on.investment.study..examines.long.term.impacts.from.an.economic.perspective..often.in.relation.to.program.costs..NS8"   


来源:https://stackoverflow.com/questions/36068960/updated-plyr-rename-not-recognizing-identical-x-error-the-following-from

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