小编use*_*257的帖子

如何将monadic数据转换为R中的二元数据(country-year到pair-year)?

我有按国家/年组织的数据,其中包含二元关系的ID.我想通过二年级组织这个.

以下是我的数据组织方式:

     dyadic_id country_codes year
  1          1           200 1990
  2          1            20 1990
  3          1           200 1991
  4          1            20 1991
  5          2           300 1990
  6          2            10 1990
  7          3           100 1990
  8          3            10 1990
  9          4           500 1991
  10         4           200 1991
Run Code Online (Sandbox Code Playgroud)

以下是我希望如何组织数据:

  dyadic_id_want country_codes_1 country_codes_2 year_want
1              1             200              20      1990
2              1             200              20      1991
3              2             300              10      1990
4              3             100              10      1990
5              4             500             200      1991
Run Code Online (Sandbox Code Playgroud)

这是可重现的代码:

dyadic_id<-c(1,1,1,1,2,2,3,3,4,4)
country_codes<-c(200,20,200,20,300,10,100,10,500,200)
year<-c(1990,1990,1991,1991,1990,1990,1990,1990,1991,1991)
mydf<-as.data.frame(cbind(dyadic_id,country_codes,year)) …
Run Code Online (Sandbox Code Playgroud)

r

4
推荐指数
1
解决办法
513
查看次数

标签 统计

r ×1