I assume that cnd.names is a vector of character strings and
landcov[ ,2] is a vector of integers in c(1:length(cnd.names).
Then
foo <- cnd.names[landcov[ ,2]]
should be what you want.
- tom blackwell - u michigan medical school - ann arbor -
On Mon, 21 Jul 2003, Andy Bunn wrote:
> I have a vector of land cover class data from a GIS:
>
> > landcov[1:10,2] #the first ten examples of a large (100k+) object
> 1 2 3 4 5 6 7 8 9 10
> 12 12 01 12 01 15 15 15 15 15
>
> etc.
>
> I also have a lookup table for the class data that gives the cover type
> as a string:
>
> > cnd.names #the look up table, i.e., landcov[3,2] == 1 == "Montane
> Meadow"
> CndVal Cnddbname
> 1 1 Montane Meadow
> 2 2 Sierran Mixed Coniferous Forest
> 3 3 Mixed Montane Chaparral
> 4 4 Jeffrey Pine-Fir Forest
> 5 5 Sierran White Fir Forest
>
> etc.
>
> How can I create an object that has the string as its value?
>
> I.e., foo[3] <- "Montane Meadow"
> I tried using apply and a custom function but couldn't get it to work.
>
> I feel like this is trivial but am stuck fast.
>
> Thanks, Andy