Hey guys, sorry for the inconvenience (this might be a hundred times answered question), but I have been searching a while and gave up about the following:
I have the following, table and data: table <- seq(255, 0, by=-1) data <- c(1,8,...) <--- doesn't matter what's in here Which would be the most efficient way to replace each data value, v_i, by table[v_i + 1] ? And, maybe more important, why is that more efficient? I used this, but I think is not the best option: for (i in 1:length(data)){ data[i] <- table[data[i]+1] } Then used mapply, that seems to work better: f<-function(x){ 255-x } mapply(f, data) Thanks guys in advance, Walter ______________________________________________ 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.