使用样条线平滑数据数天

时间:2015-11-20 22:06:52

标签: r interpolation

我想对一个月内的某些数据应用样条插值,但我唯一得到的是完全相同的数据点。有没有办法平滑这些数据而不使用完全相同的点?此外,我将如何在第15天添加结?

代码:

s1 <- data.frame(days = seq(1,30), 
                 long = 10 + rnorm(30, mean = 3, sd = 6), 
                 lat = 40 + rnorm(10, mean = 3, sd = 6), 
                 temp = rnorm(30, mean = 70))
spline(s1$days, s1$temp, n = 30)

data.frame:

   days      long      lat     temp
1     1 16.991305 52.08571 70.49724
2     2 16.587938 46.72716 69.82245
3     3 12.038953 52.36827 71.31120
4     4 12.093276 31.71284 69.67827
5     5  9.376906 47.31693 69.89268
6     6 19.852518 44.83850 71.71578
7     7  3.362539 31.13493 68.53733
8     8 10.586866 49.82680 67.94631
9     9 10.126041 54.20819 69.95206
10   10  5.843884 34.37549 71.09027
11   11 18.302414 52.08571 70.78152
12   12 18.621495 46.72716 71.97846
13   13 10.349178 52.36827 70.51998
14   14 13.697442 31.71284 70.12190
15   15 19.619312 47.31693 69.57377
16   16 18.160002 44.83850 72.35931
17   17 12.433114 31.13493 68.59803
18   18  5.329564 49.82680 69.78963
19   19 12.017927 54.20819 71.40647
20   20 18.192584 34.37549 69.86894
21   21  8.840258 52.08571 71.42631
22   22 10.673916 46.72716 70.08075
23   23 15.747151 52.36827 69.76618
24   24 15.969337 31.71284 69.45216
25   25 12.266088 47.31693 70.53574
26   26 13.771699 44.83850 69.22552
27   27  8.797278 31.13493 71.41861
28   28 14.490472 49.82680 71.81539
29   29 13.250010 54.20819 71.23150
30   30 15.527469 34.37549 70.31726

输出:

$x
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

$y
 [1] 70.49724 69.82245 71.31120 69.67827 69.89268 71.71578 68.53733 67.94631 69.95206 71.09027 70.78152 71.97846 70.51998 70.12190 69.57377
[16] 72.35931 68.59803 69.78963 71.40647 69.86894 71.42631 70.08075 69.76618 69.45216 70.53574 69.22552 71.41861 71.81539 71.23150 70.31726

0 个答案:

没有答案