[R] approxfun returning value higher than I would expect

stephen sefick ssefick at gmail.com
Wed Sep 15 21:48:08 CEST 2010


Below is the code that I am using in a much larger function.  I would
expect a bankfull measure at zero to be between 0.6 and 0.8 approxfun
is returning 0.8136986.  I am sure that I am missing something.

measure_bkf <- (structure(list(measurment_num = c(0, 0.2, 0.4, 0.6,
0.8, 1, 1.2,
1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4), bankfull_depths_m
= c(-0.48,
-0.48, -0.42, -0.26, 0.58, 0.48, 0.47, 0.54, 0.5, 0.52, 0.52,
0.56, 0.58, 0.61, 0.68, 0.62, 0.67, 0.66)), .Names = c("measurment_num",
"bankfull_depths_m"), row.names = c("6124", "612", "613", "614",
"615", "616", "617", "618", "619", "620", "621", "622", "623",
"624", "625", "626", "627", "628"), class = "data.frame"))


measure_bkf_not_zero <- subset(measure_bkf, measure_bkf$bankfull_depths_m!=0)

bkf_min <- which.max(measure_bkf_not_zero[,"bankfull_depths_m"]<0)

bkf_max <- which.max(measure_bkf_not_zero[,"bankfull_depths_m"])

#bkf_min <- ifelse(length(bkf_min)>1, bkf_min[1], bkf_min)
#bkf_max <- ifelse(length(bkf_max)>1, bkf_max[1], bkf_max)

#s <- with(measure_bkf_not_zero, approx(measurment_num,
bankfull_depths_m,
xout=seq(measure_bkf_not_zero[bkf_min,"measurment_num"],
measure_bkf_not_zero[bkf_max,"measurment_num"], length=2000)))
#int_bkf <- with(s, x[which.min(y[y>0])])

s <- with(measure_bkf_not_zero[bkf_min:bkf_max,],
approxfun(bankfull_depths_m, measurment_num), ties=mean)

int_bkf <- s(0)

-- 
Stephen Sefick
____________________________________
| Auburn University                                   |
| Department of Biological Sciences           |
| 331 Funchess Hall                                  |
| Auburn, Alabama                                   |
| 36849                                                    |
|___________________________________|
| sas0025 at auburn.edu                             |
| http://www.auburn.edu/~sas0025             |
|___________________________________|

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                -K. Mullis

"A big computer, a complex algorithm and a long time does not equal science."

                              -Robert Gentleman



More information about the R-help mailing list