Correcting Drift in R Studio Good Day,
I have a dataset of an IMU (int_os = Angle of Upper Leg) whilst cycling with (almost) the same RPMs, the IMU has a drift (a continuously increasing deviation away from the true position).

Unfortunately, I couldn't find a package/example on how to correct the drift of a dataset in R.
The end result should be a dataset int_os2 that does not contain the continous deviation (angle of the upper leg should stay the same and not 'drift').
Somewhat liket his:

I am thankful for any hints.

You could fit a smoother like loess or rolling mean and take the residuals from the fit (in the case of rolling mean that would be your datapoint minus the rolling mean). This is a simpler example of your data, but with some tweaking of the parameters you should be able to get the expected results:
x <- seq(1, 100, length.out=1000)
y <- sin(x) + seq(0, 3, length.out=length(x)) + rnorm(length(x), sd= 0.1)

plot(x, y, type='l', col='grey60')
points(x, y, pch=19)


Fit loess and plot the de-trended residuals:
fit <- loess(y ~ x)

plot(x, fit$residuals, type='l', col='grey60')
points(x, fit$residuals, pch=19)


