I would like to do a spline interpolation, but not the general way.
My data is unevenly distributed and filled with gaps.
What I would like the spline to do is not take into account a certain number of observations for interpolation but a certain window in time, eg. 10 years.
Does anyone have any idea what function to use, because the following code
name="baradla_l"
data=read.table(file=paste(name,".csv", sep=""), sep=";", header=T)
spline_fun=function(data_column, time_column, n){
x=time_column
y=data_column
splineil=spline(x,y,n)
return(splineil)
}
result=spline_fun(data[,2], data[,1], 100)
plot(result$x,result$y)
plot(result$x,result$y, type="l")
points(data[,1], data[,2],col="red")
does not seem to do the trick an I do not know what to meddle with.
The data as required:
data <- structure(list(date = 1899:2012, d18O = c(NA, NA, NA, NA, NA,
NA, NA, -7.41784, -7.04786, NA, -7.36332, NA, -8.29839, NA, -8.16167,
NA, -7.71389, NA, -7.02616, -7.4196, -6.94689, NA, NA, -6.75823,
-7.77452, NA, NA, -7.67965, -7.38529, NA, -6.83634, -7.69333,
-7.12526, -8.05093, -7.54384, -7.96867, -7.25356, NA, -7.63551,
-7.05296, -7.3081, -6.55707, -6.58208, -6.38919, -7.74052, -8.13889,
NA, -7.34376, -7.09647, -7.18969, -7.27335, NA, -7.50431, NA,
-7.67371, NA, NA, NA, NA, NA, -7.51227, NA, -7.68565, NA, -7.14066,
NA, NA, -7.66135, NA, -7.41493, NA, NA, -7.16749, NA, NA, -7.52235,
NA, NA, -7.57791, NA, NA, -6.83033, NA, -7.63777, NA, NA, -7.62713,
-7.51122, NA, NA, -7.80703, NA, -7.41753, -8.21293, NA, NA, NA,
NA, -7.96513, NA, -7.66993, NA, -7.45512, NA, -6.96408, NA, -7.15501,
NA, -7.87707, -8.28378, NA, -7.75944, NA, NA)), .Names = c("date",
"d18O"), class = "data.frame", row.names = c(NA, -114L))