Skip to content
Prev 108583 / 398500 Next

indexing without looping

Hello,
I've got a data.frame like this:
value class
1   6.5     1
2   7.5     3
3   8.5     5
4  12.0     2
and a long vector of classes like this:
And would like to obtain  a vector of length = length(x), with the
corresponding values extracted from assignation table. Like this:
[1]  6.5  6.5 12.0   NA   NA  8.5   NA  7.5 12.0 12.0 12.0

Could you help me with an elegant way to do this ?
(I just can do it with looping for each class in the assignation table,
what a think is not perfect in R's sense)

Wishes,
Javier