【发布时间】:2022-01-16 20:31:45
【问题描述】:
如何合并两个结构不同的表?就像,我想将“ds_categories”中的类别名称与“ds”中的类别ID交叉。 ds 有 1109383 行,ds_categories 有 2775 行。更具体地说,我想将类别名称链接到类别 ID。 这个完整的数据库位于 kaggle:https://www.kaggle.com/sp1thas/book-depository-dataset/code
ds_categories
category_id category_name
1 1998 .Net Programming
2 176 20th Century & Contemporary Classical Music
3 3291 20th Century & Contemporary Classical Music
4 2659 20th Century History: C 1900 To C 2000
5 2661 21st Century History: From C 2000 -
6 1992 2D Graphics: Games Programming
ds
authors bestsellers.rank categories
1 [1] 49848 [214, 220, 237, 2646, 2647, 2659, 2660, 2679]
2 [2, 3] 115215 [235, 3386]
3 [4] 11732 [358, 2630, 360, 2632]
4 [5, 6, 7, 8]114379 [377, 2978, 2980]
5 [9] 98413 [2813, 2980]
6 [10, 11] 90674 [1520, 1532]
我试过了,但没用:
join_cat <- merge(ds, ds_categories, by.x = "categories", by.y = "category_id", all.x = TRUE, all.y = FALSE)
【问题讨论】: