I have two datasets in which at several time points a certain value is measured. I would like to visualize the ratio between the two datasets with a line chart. However, the time points of the measurements do not overlap completely and some experiments contain more values than others.

**Data**

```
df_1 <- as.data.frame(cbind(c(1,2,3,4,5,6,7,8,9,10), c(1,4,7,8,9.5,17,41,27, 26, 10)))
df_2 <- as.data.frame(cbind(c(0.1, 0.5, 2, 3, 4.4,5.3,6,7,8,10,12,15,16,20), c(0.1,2,4,6,7.5,6.3,9,19,22,23,24,51,31,23)))
```

**Plots**

```
library(tidyverse)
ggplot()+
geom_line(data = df_1, aes(x=V1, y=V2), col = "black") +
geom_line(data = df_2, aes(x=V1, y=V2), col = "red")
```

Next, I would like to plot the ratio between the two curves. However, since the measured data-points are not evenly spaced (and measured at slightly different times), I am not able to simply divide the value for each time point and plot the result.

**Question**

How do you calculate the ratio between two unevenly spaced dataframes (which can be of different lengths) in R?

**Additional example**

I have two (example) datasets. The third dataset is the expected output (`df_3`

). The green line represents the expected output: the ratio between `df_2`

/`df_1`

.

```
df_1 <- as.data.frame(cbind(time = c(1:5), value = c(1:5)))
df_2 <- as.data.frame(cbind(time = c(1.5, 2, 3,4), value = c(2,2,2.5,3.5)))
df_3 <- as.data.frame(cbind(time = c(1.5, 2, 3,4), value = c(1.33, 1, 0.83, 0.875)))
ggplot() +
geom_point(data = df_1, aes(x=time, y=value), col = "black", size = 3) +
geom_point(data = df_2, aes(x=time, y=value), col = "red", size =3) +
geom_line(data = df_1, aes(x=time, y = value), col = "black") +
geom_line(data = df_2, aes(x = time, y = value), col = "red") +
geom_point(data =df_3, aes(x = time, y = value), col = "green", size = 3) +
geom_line(data=df_3, aes(x=time, y = value), col = "green")
```

You can do a full join using the

`dplyr`

package. Note that the data frames I am using are the same as yours but the columns are named`time`

and`value`

.Linear interpolation on the ratioLinear interpolation of value_1 on df_2