代码之家  ›  专栏  ›  技术社区  ›  user3292755

按字符类型在R中左连接

  •  0
  • user3292755  · 技术社区  · 6 年前

    我试图从两个不同的网站上抓取电影集

    我想把这两个信息结合起来,用电影的片名把它们联系起来。下面是第一个数据集

    structure(list(event_name = c("maze runner: the death cure", "star wars: the last jedi", 
    "spider-man: homecoming"), event_start_time = structure(c(100, 
    200, 300), class = "Date"), movie_sold_all = c(100L, 200L, 
    300L)), .Names = c("event_name", "event_start_time", "movie_sold_all"
    ), row.names = c(NA, 3L), class = "data.frame")
    

    这是我收集的第二个数据集

    enter image description here 我必须上传图像,因为有>10列

    我希望能加入 movie_title 所以他们会把这两个信息结合起来。基本相似 left join 在SQL中

    我试过了 merge( df_bq_movies,movies,by.y="movie_title",all.x = TRUE)

    但出现了错误

    Error in merge.data.frame(df_bq_movies, movies, by.y = "movie_title", :'by.x' and 'by.y' specify different numbers of columns

    有关详细信息,这是数据集的维度

    data 1 : 605 rows , 3 column data 2 : 509 rows , 21 column

    1 回复  |  直到 6 年前
        1
  •  2
  •   Aramis7d    6 年前

    使用merge时,必须同时定义 by.x by.y 如果两个数据集上的列名相同,则可以使用 by 相反

    e、 g。

     merge( df_bq_movies, movies, by.x = "event_name", by.y = "movie_title")