问题
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