Hello, I have two character vectors: list.a and list.b. Every element of list.a appears somewhere in list.b. Not all elements of list.b are in list.a, and some elements of list.b appear multiple times in list.a. I want to create a new vector (index) of the same length as list.a where the nth element of index is the location in list.b of the nth element of list.a.
This code will work, but I have heard over and over again that using loops is inefficient in R and that there are (almost always) better ways to do things. for(i in 1:length(list.a)){ index[i] <- seq(1,length(list.b))[list.b==list.a[i]] } Thank you, Mitch ______________________________________________ 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.