【发布时间】:2020-11-17 16:28:43
【问题描述】:
我的数据看起来像这样
zz <- 'wb_iso3c country year wbclass
1: YUG "Serbia and Montenegro (former)" 1990 NA
2: YUG "Yugoslavia (former)" 1990 UM
3: YUG "Yugoslavia (former)" 1991 NA
4: YUG "Serbia and Montenegro (former)" 1991 UM
5: YUG "Serbia and Montenegro (former)" 1992 NA
6: YUG "Yugoslavia (former)" 1992 NA'
Data <- read.table(text=zz, header = TRUE)
在以下情况下,我想找到一种系统有效地放弃观察的方法:
仅考虑wb_iso3c 和year,我的观察结果是重复的。 (因此我不在乎另一个变量,例如 country 是否具有不同的值)。在“重复”的观察中,我想保留
wbclass 不是 NA 的观察结果。如果
wbclass 是 NA 对于两个观察结果,保留哪一行无关紧要。
最终的数据集应该是这样的
wb_iso3c country year wbclass
1: YUG Yugoslavia (former) 1990 UM
2: YUG Serbia and Montenegro (former) 1991 UM
3: YUG Serbia and Montenegro (former) 1992 <NA>
非常感谢您的帮助。如果你可以使用 dyplr 的 data.table 那就太好了。
【问题讨论】:
标签: r data-manipulation missing-data