Sunday, 8 September 2013

Return a value given its position

Return a value given its position

I am trying to create a vector with the values from an ordered number-set
given its position. The values for the respective position is in a single
column vector. I would therefore like the result to be in a vector.
Something like this:
x.numbers <- c(100,120,140,160,180,200) #The ordered numbers
pos<-c(1,1,3,2,1,2,2,4,4,4,1,3,2,3,3,3,1,1,1,1), position<-cbind(pos)
#Vector with respective position
The answer I am looking for should return the vector:
Value
[1,] 100
[2,] 100
[3,] 140
[4,] 120
[5,] 100
[6,] 120
[7,] 120
[8,] 160
Is there a way to accomplish this without using a loop? Any suggestions
would be appreciated.

No comments:

Post a Comment