我試圖合併兩個數據集,按年份和國家/地區。第一組數據(df = GNIPC)代表1980-2008年間每個國家的人均國民收入。在兩個數據集中合併基於多於1列的數據集
Country Year GNIpc
(chr) (dbl) (dbl)
1 Afghanistan 1990 NA
2 Afghanistan 1991 NA
3 Afghanistan 1992 2010
4 Afghanistan 1993 NA
5 Afghanistan 1994 12550
6 Afghanistan 1995 NA
第二個數據集(DF =制裁)代表從1946年到今天的經濟制裁。
country imposition sanctiontype sanctions_period
(chr) (dbl) (chr) (chr)
1 Afghanistan 1 1 6 8 1997-2001
2 Afghanistan 1 7 1979-1979
3 Afghanistan 1 4 7 1995-2002
4 Albania 1 2 8 2005-2005
5 Albania 1 7 2005-2006
6 Albania 1 8 2004-2005
我想合併這兩個數據集,這樣,每一年GNI我要麼必須在該國存在與否的制裁。對於GNI年來不在sanctions_period值是0,對於那些這將是1.這就是我想要它看起來像:
Country Year GNIpc Imposition sanctiontype
(chr) (dbl) (dbl) (dbl) (chr)
1 Afghanistan 1990 NA 0 NA
2 Afghanistan 1991 NA 0 NA
3 Afghanistan 1992 2010 0 NA
4 Afghanistan 1993 NA 0 NA
5 Afghanistan 1994 12550 0 NA
6 Afghanistan 1995 NA 1 4 7
我不會用那種格式的第二個數據集。如果有人向我提供這些數據,我會(1)畏縮,(2)開始工作,以便每個'sanctiontype'組合和每個'sanctions_period'組合中都有一行。所以'Afganistan'將有五行,其中'sanctiontype = 1',每個年份爲1997 - 2001年。 – joran
阿富汗1998年應該是什麼樣子?每個制裁週期(2)都是一行,還是一行「1 4 6 7 8」? – Chris
我已經完成了一個不同的數據集,其中每個制裁類型都有自己的行。在這裏,我正在尋找一種方法來確定每個GNI年份當年是否存在制裁。回顧過去的制裁類型,我該怎麼做? – MB92