I have a problem with two vectors with different lengths. I would like realise the subtraction between the values of the two vectors where the time is the same.
For example:
theo <- data.frame(
time = seq(236.4, 850, by = 0.01),
val = seq(0, 6136, 0.1)
)
obs <- data.frame(
time = c(260.76, 270.53, 288.44, 308.15,
310.12, 319.38, 335.25),
val = c(1, 8, 10, 5, 0.2, 6, 5)
)
I tried
with(theo[theo$time==obs$time,],sum((obs$val -theo$val)^2))
But that didn't work.