
Dear R-helpers,
I'm trying to associate linear coefficients (intercept and slope) to tens of thousands of observations based on a table with benchmark values.
#####Example - Value table and their corresponding coefficients (intercept and slope)
coef = data.frame(cbind(st=c(1:5),b = runif(5,0.3,5),a = seq(0.5,5,1)))print(coef)
#Example of observations to be computedobs = runif(20,1,5)print(obs)

#This should be fairly simple - but I can't get the loop structure out of my head. I don't know how to tell the software "if the observation is greater than st[i-1] but smaller than st[i], use a[i] and b[i] - otherwise go to the next line".So far, I've tried this:
for(t in 1:length(obs)) {
	for(i in 1:length(coef$st)) if(coef$st[i-1] < obs[t] < coef$st[i]) x[t] = coef$b[i] + (coef.$a[i] * obs[t])
	}#####						
Doesn't work - if statement do not accept double conditions structure (y[-1] < x < y) and I should put an else statement - but i'm stuck there. I have the feeling I should look into lapply but it doesn't seem like lapply works with "if" statements.
Any tips would be much appreciated,
Thanks,


Mathieu Beaulieu,
Soil, Water & Environment Laboratory
Institute for Resources, Environment and Sustainability
University of British-Columbia
429-2202 Main Mall,
Vancouver, BC,
V6T 1Z4
Canada





 		 	   		  
	[[alternative HTML version deleted]]

