I have a data frame including a motion signal sampled at 100Hz. In a simplified way it looks like this:
df<-data.frame(c(0.01, 0.02, 0.05, 0.06), c(0, 0, 2, 0), c(2,3,10,15))
names(df)<-c("counter", "lostSamples", "value")
df
# counter lostSamples value
# 1 0.01 0 2
# 2 0.02 0 3
# 3 0.05 2 10
# 4 0.06 0 15
counter” is each sample; “lostSamples” is when my device could not record/store the sample; “value” is the actual signal in 1 dimension relative to a reference
I would like to add rows when there are lost samples. In this example I have to fill the gap (add rows to data frame) for counters 0.3 and 0.4. I would like to fill the gaps either with NAs (easier) or interpolating by a linear function depending on values before and after the gap.
I tried with for loops and with apply but was not successful.