How to interpolate soil depth values using "spline"? Or using the "aqp" package?

1
Hello, I would like to interpolate the soil depth values in columns "top" and "bottom" , (every 5 units) in the soil data, such as in the dataframe:

id_num    id_name horiz  top bottom  K   Mg   Ca CEC_7 ex_Ca_to_Mg sand silt clay   CF
1          colusa    A   0      12 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
2          colusa  ABt   12     28 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
3          colusa  Bt1   28     52 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
5           glenn    A   0       9 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
6           glenn   Bt   9      34 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84

So I have (top-bottom = 0-12, 12-28, 28-52, ...) and I would like to get < "top" and "bottom" columns interpolated by 5 units (cm in this case) such as (top-bottom = 0-5, 5-10, 10-15, 15-20, 20-25, 25-30, 30-35, 35-40, 40-45, 45-50, ...) , interpolating values and repeating the other corresponding columns such as id_num , id_name and horiz , such as:

id_num    id_name horiz  top bottom  K   Mg   Ca CEC_7 ex_Ca_to_Mg sand silt clay   CF
1          colusa    A   0       5 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
1          colusa    A   5      10 0.3 25.7  9.0  23.0        0.35   46   33   21 0.12
2          colusa  ABt   10     15 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
2          colusa  ABt   15     20 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
2          colusa  ABt   20     25 0.2 23.7  5.6  21.4        0.23   42   31   27 0.27
3          colusa  Bt1   25     30 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   30     35 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   35     40 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   40     45 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
3          colusa  Bt1   45     50 0.1 23.2  1.9  23.7        0.08   40   28   32 0.27
5           glenn    A   0       5 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
5           glenn    A   5      10 0.2 21.9  4.4  18.8        0.20   54   20   25 0.55
6           glenn   Bt   10     15 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   15     20 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   20     25 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   25     30 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84
6           glenn   Bt   30     35 0.3 18.9  4.5  27.5        0.20   49   18   34 0.84

Note: In this example values are not interpolated (just repeated).

The sample dataset can be viewed with the command data(sp4) .

I tried the slice function of the aqp package with:

data(sp4) #obter o conjunto de dados de solo de exemplo
depths(sp4) <- id ~ top + bottom #ajustar os dados para o pacote 'aqp' package
sliced <- slice(sp4, fm= c(0,5,10,15,20,25,30,35,40,45,50) ~ sand + silt + clay + name + ex_Ca_to_Mg, just.the.data=TRUE)

But I got:

(top-bottom = 0-1, 5-6, 10-11, 15-16, 20-21, 25-26, 30-31, 35-36, 40-41, 45-46, ...)

instead of:

(top-bottom = 0-5, 5-10, 10-15, 15-20, 20-25, 25-30, 30-35, 35-40, 40-45, 45-50, ...)

I also tried the slab function, but it did not work with me, yet.

Suggestions with spline are very welcome!

Thank you!

    
asked by anonymous 26.01.2018 / 14:44

1 answer

2

1) First you will have to rearrange your table, so that each column represents a solo profile.

2) The range of values to predict must be 'NA'. Ex:

0.3
NA
NA
0.2

3) Install library(zoo) ;

4) Organize all your data in data.frame(); use the na.spline():

data.frame('id' = c(1, 2, NA, 4, 6, NA, NA, NA, 6.5)) -> exemplo
na.spline(exemplo) -> exemplo_preenchido
print(exemplo_preenchido)
    
29.01.2018 / 14:25