Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread David Wolfskill
On Fri, Sep 11, 2015 at 04:42:07PM +0200, peter dalgaard wrote: > Or change the data format slightly and use indexing: > > > l > keyval > [1,] "1.1" "1" > [2,] "1.9" "1" > [3,] "1.4" "15000" > [4,] "1.5" "2" > [5,] "1.15" "25000" > > v <- l[,2] > > names(v) <- l[,1] >

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread peter dalgaard
Or change the data format slightly and use indexing: > l keyval [1,] "1.1" "1" [2,] "1.9" "1" [3,] "1.4" "15000" [4,] "1.5" "2" [5,] "1.15" "25000" > v <- l[,2] > names(v) <- l[,1] > x <- c("1.9", "1.9", "1.1", "1.1", "1.4", "1.4", "1.5", "1.5", "1.5", + "1.5") > v[x]

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-11 Thread David Wolfskill
On Thu, Sep 10, 2015 at 10:30:50PM -0700, Bert Gunter wrote: > ?match > > as in: > > > y <- lk_up[match(x,lk_up[,"key"]),"val"] > > y > [1] "1" "1" "1" "1" "15000" "15000" "2" > [8] "2" "2" "2" > ... Aye -- thank you very much! Peace, david -- David H. Wolfski

Re: [R] Generate a vector of values, given a vector of keys and a table?

2015-09-10 Thread Bert Gunter
?match as in: > y <- lk_up[match(x,lk_up[,"key"]),"val"] > y [1] "1" "1" "1" "1" "15000" "15000" "2" [8] "2" "2" "2" Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On

[R] Generate a vector of values, given a vector of keys and a table?

2015-09-10 Thread David Wolfskill
I apologize in advance: I must be overlooking something quite simple, but I'm failing to make progress. Suppose I have a "lookup table": Browse[2]> dput(lk_up) structure(c("1.1", "1.9", "1.4", "1.5", "1.15", "1", "1", "15000", "2", "25000"), .Dim = c(5L, 2L), .Dimnames = list( NU