问题
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