Dear R-Helpers:

I am a entry level user of R.

Have the following question. Many thanks in advance.


# value.vec stores values
value.vec <- c('a','b','c')
#  which.vec stores the locations/indexs of values in value.vec.
which.vec <- c(3, 2, 2, 1)
# How can I obtain the following vector based on the value.vec and which.vec
mentioned above
# vector.I.want <- c('c', 'b', 'b', 'a')
#                          3    2    2    1


# I try to avoid using the following loop to achieve the goal because the
which.vec in reality will be very long

vector.I.want <- rep(NA,length(which.vec))
for (i in 1:length(which.vec))
{ vector.I.want[i] <- value.vec[which.vec[i]] }

# is there a faster way than looping?

Thanks in advance.

-Sean

	[[alternative HTML version deleted]]

