I am trying to figure out a method to increase the number of elements of vectors, in order to remove the angular effect visible when I plot the values of these vectors. For instance, let’s say I got two vectors containing 10 elements each:
a = c(4,2,10,5,3,4,8,9,6,2)
b = seq(0,4.5, by=0.5)
They are subject to data smoothing, but I would like to increase their “resolution” to obtain more prediction points than 10 (its length). So, in other words, take the vector a and double (for example) its number of elements, while keeping its consistency. The resulting vector should be something like:
a = c(4,3,2,6,10,7,5,4,3,4,6,8,8.5,9,7.5,6,4,2,2)
Of course, in this particular case, I can easily compute the average of the elements pair-wise. But I would like to have a generalized method for an arbitrary length. I have tried with:
seq(a[1],a[10], length.out=20)
but of course this does not do the job as only the first and last element of the vector are taken in consideration. It is suitable for the second vector b though (which contains the abscissa values).
Any help would be appreciated. Thanks.
Marius.
Do you just want linear interpolation based on the
bsequence?See
?approxfor other options and itsSee alsofor other forms of interpolation, also?roundfor rounding out the values in various ways.