【发布时间】:2020-01-09 03:09:15
【问题描述】:
IMDb 数据集文件中的一个文件 (title.principals) 包含有关演员和工作人员的详细信息。 我想提取导演的详细信息并将它们合并到单行中,因为每部电影可以有多个导演。 有可能吗?
#title.principals file download
url <- "https://datasets.imdbws.com/title.principals.tsv.gz"
tmp <- tempfile()
download.file(url, tmp)
#file load
title_principals <- readr::read_tsv(
file = gzfile(tmp),
col_names = TRUE,
quote = "",
na = "\\N",
progress = FALSE
)
#name.basics file download
url <- "https://datasets.imdbws.com/name.basics.tsv.gz"
tmp <- tempfile()
download.file(url, tmp)
#file load
name_basics <- readr::read_tsv(
file = gzfile(tmp),
col_names = TRUE,
quote = "",
na = "\\N",
progress = FALSE
)
#extract directors data
df_directors <- title_principals %>%
filter(str_detect(category, "director")) %>%
select(tconst, ordering, nconst, category) %>%
group_by(tconst)
df_directors <- df_directors %>% left_join(name_basics)
head(df_directors, 20)
我将它与 name_basics 文件一起加入,以获得导演姓名。 姓名基础包含姓名、生卒年、职业。 在这一步之后,我想将每部电影的所有导演合并到一个以逗号分隔的单元格中。
有没有可能?
【问题讨论】:
-
name_basics的内容是什么?你需要stackoverflow.com/questions/15933958/… 吗? -
合并每部电影的所有导演
df_directors中的电影名称在哪里? -
没有电影名称。有 ID tconst。与其他文件的导演合并后将添加标题。
标签: r merge concatenation