我的数据针对每个制裁年的制裁。有5种类型的有针对性的制裁,但由于我有兴趣全面了解制裁,而不是其特定类型,所以我想创建一个新的专栏,表示是否在特定年份实施全面的针对性制裁。从4个变量创建单列
df1 <- data.frame(Country = 'Angola',
Asset_freeze = c(1, 0),
Sectoral = c(1, 0),
Commodity = c(1, 0),
Diplomatic = c(1, 0),
Individual = c(1, 0),
Year = c('1993', '1994', '1995')
Country Asset_freeze Sectoral Commodity Diplomatic Individual Year
(chr) (dbl) (dbl) (dbl) (dbl) (dbl) (int)
1 Angola 0 1 1 0 0 1993
2 Angola 0 1 1 0 0 1994
3 Angola 0 1 1 0 0 1995
我想它看起来像如下:
Country Year Sanctions
(chr) (int) (dbl)
1 Angola 1993 1
2 Angola 1994 1
3 Angola 1995 1
如何我能得到这个?由于
在哪种情况下'Sanctions'为0? –
您的输入数据集代码给了我错误 – akrun
您能否更专注于编码问题而不是您正在应用的特定问题来描述您的问题?我们不应该解释你的意思是制裁。你的意思是每年的中间五列是否有非零条目? @akrun:我认为这是最后一个缺失的支架。 – Bazz