Skip to content
Prev 7563 / 29559 Next

Use of lookup table to create new matrix

Ian,

As you need interpolation, perhaps the loess function is useful for
you  ((although I wonder whether you need a lookup table. Wouldn't you
rather use an existing function to predicts svp from temp))?

tab = data.frame(temp=-10:9,svp= 1:20)
mat = matrix(20:-29, byrow=T, nrow=5)/2
mat

model = loess(svp~temp, data=tab)
mat2 = predict(model, as.vector(mat))
dim(mat2) = dim(mat)
mat2

# only matching integers:
m = cbind(as.vector(mat), 1:length(mat))
m = merge(m, tab, by=1, all.x=T)
m = m[order(m[,2]), 3]
dim(m) = dim(mat)
m


Robert
On Thu, Feb 4, 2010 at 1:12 AM, Ian McCallum <mccallum at iiasa.ac.at> wrote: