Left join in R by character type

ぐ巨炮叔叔 提交于 2020-01-06 07:28:31

问题


am trying to scrape movie sets from 2 different websites

And I want to combine these 2 informations, and tied them up using the movie title name. Here is the first dataset looks like

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")

And this is the 2nd dataset that i've scraped

I have to upload image only since there are >10 columns

What i expect to have is to join the movie_title so they it'll incorporate these 2 informations. Basically similar like left join in SQL

I've tried merge( df_bq_movies,movies,by.y="movie_title",all.x = TRUE)

but the error occurs

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

For more information, this is the dimension of the dataset

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


回答1:


With merge you have to define both by.x and by.y if the column name is the same on both datasets you can just use by instead.

e.g.

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


来源:https://stackoverflow.com/questions/49250513/left-join-in-r-by-character-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!