我有大量数据,我需要在标准高度找到几个变量的值。我想对其他变量的值进行线性插值Height=c(0,100,200,250,400,500)
,并将它们作为新列添加到现有数据中。这是我试图将一个变量的值作为标准Height=c(0,100,200,250,400,500)
。这仅适用于一个变量:
data2<-approx(data2$Height,data2$ozone,xout=c(0,100,200,250,400,500))
预期的结果应该是一个 18 行 4 列的数据框。
这是示例数据(data2)
:
ozone Height Temp Wind
23.224833 0.000000 253.005798 3.631531
23.750044 35.218689 253.299332 5.178889
24.589071 70.661133 253.538574 6.892455
25.619747 106.267334 253.492661 8.050934
26.443541 142.014648 253.279053 8.648781
27.235945 213.897034 252.815262 9.263882
27.698713 286.280518 252.10556 9.269853
27.865248 359.172363 251.390045 9.3006
28.361752 432.788086 251.379913 8.90488
30.279163 507.276733 251.849655 7.817647
23.048151 0.000000 251.528275 4.174027
23.477306 34.998413 251.6698 5.630364
24.16725 70.187622 251.759369 7.237537
25.239206 105.544006 251.744934 8.859097
26.319073 141.05011 251.601654 9.928196
27.409718 212.47052 251.214279 10.75243
27.825275 284.45282 250.738007 10.812123
28.214966 357.184631 250.87706 9.980968
29.726873 430.919983 251.84964 9.139032
32.482925 505.574097 252.471924 8.063484
22.369734 0.000000 250.876144 3.82036
22.916582 34.908447 251.044205 5.281044
23.732521 70.014038 251.170456 6.970277
24.998178 105.296021 251.221603 8.801399
26.30809 140.736084 251.133591 10.039667
27.572966 212.052795 250.852631 11.118568
28.233795 283.998474 250.61908 10.677624
29.079391 356.812012 251.179962 9.466641
31.244007 430.597534 252.042175 9.016301
33.636559 505.305542 252.659393 8.103294
预先感谢您的帮助。
更新
这是所需的答案:
Height ozone Temp Wind
0 23.22483 253.0058 3.631531
100 25.43833 253.5007 7.847021
200 27.08275 252.9049 9.144964
300 27.73006 251.9709 9.275640
400 28.14061 251.3844 9.081132
500 30.09185 251.8038 7.923858
0 23.04815 251.5283 4.174027
100 25.07112 251.7472 8.604831
200 27.21928 251.2819 10.608513
300 27.90858 250.7677 10.634455
400 29.09287 251.4418 9.492087
500 32.27714 252.4255 8.143790
0 22.36973 250.8761 3.820360
100 24.80820 251.2139 8.526537
200 27.35920 250.9001 10.936230
300 28.41962 250.7423 10.411498
400 30.34638 251.6846 9.203049
500 33.46665 252.6156 8.168133