I have two datasets for example, which have different lengths, how to get reductions in the common time period? I give the sample data below to explain what I meant.
DF1
year value
1981 350
1982 910
1983 500
1984 312
1986 460
1987 510
DF2
year value
1983 311
1984 550
1985 270
1986 480
1987 499
1988 560
1989 570
1990 601
I want to have a new dataframe, which shows the difference between the two in common years. I used DF1$value - DF2$value, but it says that "‘-’ only defined for equally-sized data frames". Also, in DF1, the years are not consecutive, 1984, 1986, etc. In the new dataframe, it could show NA value or dismiss the year 1985 but have values for the other common years. And the new dataframe should have a column named "year" as well. How to do this? Thanks for your help.