0

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"))
Sam
  • 281
  • 4
  • 10
  • UPDATE: I'm also getting more of these The following `from` values were not present in `x`: errors when I run the R script from source(). Renames that work with manual selection are not working with a source() call. Others work as if everything is okay. Very strange. – Sam Mar 18 '16 at 14:04

1 Answers1

0

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"   
Wyldsoul
  • 1,468
  • 10
  • 16
  • That works, but really looking to use rename to ensure match of origin and code name. Data set has 700+ columns. – Sam Mar 17 '16 at 19:23