问题
I have the following data frame
ref_dat
k Intensity Slope
1 0.021467214 33 16
2 0.012444759 33 8
3 0.006079156 33 4
4 0.003792025 33 2
5 0.022765086 47 16
6 0.017335375 47 8
7 0.007279113 47 4
8 0.003396341 47 2
9 0.034101951 75 16
10 0.023045525 75 8
11 0.009163758 75 4
12 0.003253822 75 2
13 0.039832629 110 16
14 0.029826826 110 8
15 0.010529787 110 4
16 0.002945170 110 2
17 0.042140630 155 16
18 0.032338534 155 8
19 0.013758171 155 4
20 0.002605399 155 2
I am trying to get the interpolated (and extrapolated) values of k for a given set of slope and intensity using interp function in akima, so I am doing the following.
my new slope
s=10
my new intensities
i=c(seq(0,50,5),rev(seq(0,50,5)))
and calculating new k values
k_new=interp(x=ref_dat$Intensity,y=ref_dat$Slope,z=ref_dat$k,xo=i,yo=s,extrap = FALSE)$z
and the result is
k_new
[,1]
[1,] NA
[2,] NA
[3,] NA
[4,] NA
[5,] NA
[6,] NA
[7,] NA
[8,] 0.01539903
[9,] 0.01714568
[10,] 0.01850739
[11,] 0.01930460
[12,] 0.01930460
[13,] NA
[14,] NA
[15,] NA
[16,] NA
[17,] NA
[18,] NA
[19,] NA
[20,] NA
[21,] NA
[22,] NA
turning extrapolation on
k_new_ext=interp(x=ref_dat$Intensity,y=ref_dat$Slope,z=ref_dat$k,xo=i,yo=s,extrap = TRUE)$z
and the reult
k_new_ext
[,1]
[1,] NA
[2,] NA
[3,] NA
[4,] NA
[5,] NA
[6,] NA
[7,] NA
[8,] 0.01539903
[9,] 0.01714568
[10,] 0.01850739
[11,] 0.01930460
[12,] 0.01930460
[13,] NA
[14,] NA
[15,] NA
[16,] NA
[17,] NA
[18,] NA
[19,] NA
[20,] NA
[21,] NA
[22,] NA
exploring the result a bit
cbind(i,k_new,k_new_ext)
i
[1,] 0 NA NA
[2,] 5 NA NA
[3,] 10 NA NA
[4,] 15 NA NA
[5,] 20 NA NA
[6,] 25 NA NA
[7,] 30 NA NA
[8,] 35 0.01539903 0.01539903
[9,] 40 0.01714568 0.01714568
[10,] 45 0.01850739 0.01850739
[11,] 50 0.01930460 0.01930460
[12,] 50 0.01930460 0.01930460
[13,] 45 NA NA
[14,] 40 NA NA
[15,] 35 NA NA
[16,] 30 NA NA
[17,] 25 NA NA
[18,] 20 NA NA
[19,] 15 NA NA
[20,] 10 NA NA
[21,] 5 NA NA
[22,] 0 NA NA
Why I am getting NA values, even when the new intensity values are with in the range of values in ref_dat? Making extrap=TRUE doesn't solve my problem either.
来源:https://stackoverflow.com/questions/43003065/r-understading-na-values-in-the-result-of-akimainterp