【发布时间】:2020-03-04 16:55:45
【问题描述】:
下午好,我不是原子向量方面的专家,但我想了解一下它
我有电影“Coco”的剧本,我希望能够获得以 1.、2.、... 形式编号的行(整部电影共有 130 个场景)。我想将电影的每个场景的行转换为包含“场景1”,“场景2”,直到“场景130”的一行并依次实现。
url <- "https://www.imsdb.com/scripts/Coco.html"
coco <- read_lines("coco2.txt") #after clean
class(coco)
typeof(coco)
" 48."
[782] " arms full of offerings."
[783] " Once the family clears, Miguel is nowhere to be seen."
[784] " INT. NEARBY CORRIDOR"
[785] " Miguel and Dante hide from the patrolman. But Dante wanders"
[786] " off to inspect a side room."
[787] " INT. DEPARTMENT OF CORRECTIONS"
[788] " Miguel catches up to Dante. He overhears an exchange in a"
[789] " nearby cubicle."
[797] " 49."
[798] " And amigos, they help their amigos."
[799] " worth your while."
[800] " workstation."
[801] " Miguel perks at the mention of de la Cruz."
[809] " Miguel follows him."
[810] " 50." # Its scene number
[811] " INT. HALLWAY"
s <- grep(coco, pattern = "[^Level].[0-9].$", value = TRUE)
我的解决方案是错误的,因为它不是顺序的
v <- gsub(s, pattern = "[^Level].[0-9].$", replacement = paste("Scene", sequence(1:130)))
[1] " Scene1"
[2] " Scene1"
[3] " Scene1"
[4] " Scene1"
[5] " Scene1"
[6] " Scene1"
【问题讨论】:
-
您试图用
grep(coco, pattern = "[^Level].[0-9].$", value = TRUE)查找文本中的哪些字符串 -
library(readr) coco imsdb.com/scripts/Coco.html", skip = 238, skip_empty_rows = TRUE, locale = default_locale()) coco ]+>", "", coco) coco
-
请。运行前面的代码,我可以找到为什么我使用 [^ level] 在我的 r 脚本中不包含 level 的原因
标签: r text character readr tidytext