Skip to content

Instantly share code, notes, and snippets.

@houshuang
Created May 22, 2013 20:22
Show Gist options
  • Save houshuang/5630587 to your computer and use it in GitHub Desktop.
Save houshuang/5630587 to your computer and use it in GitHub Desktop.
replace <- list(c("Academic / Professor", "Academic/Professor"),
c("Lifelong learner", "Lifelong Learner"),
c("Student (University/College)", "Student"))
for(e in replace) {
db$usercat <- replacefact(db$usercat, e[1], e[2])}
@houshuang
Copy link
Author

replacefact <- function(x, y, z, ...) {
  x <- as.character(x)
  x[x == y] <- z
  as.factor(x)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment