1

I am trying to create a function in R that acts the same way as the "Reclassify" node in SPSS modeler. The function below has 3 arguments but it doesn't seem to be working and I'm not sure why.

column <- iris$Species
list.of.names <- c("setosa","versicolor")
new.name <- "some flowers"

reclassify <- function(column, list.of.names, new.name){
  new.name.vec <- rep(new.name, length(list.of.names))
  require(plyr)
  column <- mapvalues(column, from = list.of.names, to = new.name.vec)
}

Why doesn't this change the two factor names to "some flowers" ?

2
  • 1
    Because of scope.. You need to assign column to the function result, i.e. column <- reclassify(column, list.of.names, new.name) Nov 22, 2015 at 5:10
  • That makes sense. It works now. Thanks!
    – Warner
    Nov 22, 2015 at 5:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.