I've looked but I cannot find a more elegant solution. I would like to be able to scan through a data.frame and remove multiple and various instances of certain contents.
A trivial example is below. It works, it just seems like there should be a one line solution. #Example data: a <- data.frame(V1=1:3,V2=c(paste(LETTERS[1],LETTERS[1:3],sep='')),options(stringsAsFactors = FALSE)) #> a # V1 V2 #1 1 AA #2 2 AB #3 3 AC #Cumbersome solution (which would be even more cumbersome with real data) indices.of.aa <- which(a$V2 %in% "AA") indices.of.ab <- which(a$V2 %in% "AB") indices.of.ac <- which(a$V2 %in% "AC") a$V2 <- replace(a$V2, indices.of.aa, "c") a$V2 <- replace(a$V2, indices.of.ab, "d") a$V2 <- replace(a$V2, indices.of.ac, "e") ## output #> a # V1 V2 #1 1 c #2 2 d #3 3 e I know with the trivial example above there are extremely simple solutions but my data.frame is a few thousand rows. Thanks all. Trevor [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.