Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文本添加到r中的原子(字符)向量_R_Text_Character_Readr_Tidytext - Fatal编程技术网

将文本添加到r中的原子(字符)向量

将文本添加到r中的原子(字符)向量,r,text,character,readr,tidytext,R,Text,Character,Readr,Tidytext,下午好,我不是原子向量方面的专家,但我想了解一些关于原子向量的想法 我有电影“Coco”的脚本,我希望能够得到一行,以1,2。,的形式编号。。。(整部电影有130个场景)。我想将电影中每个场景的行转换成一行,其中包含“场景1”、“场景2”以及“场景130”,并按顺序实现它 url <- "https://www.imsdb.com/scripts/Coco.html" coco <- read_lines("coco2.txt") #after clean class(coco)

下午好,我不是原子向量方面的专家,但我想了解一些关于原子向量的想法

我有电影“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)

url我不清楚
[^Level]
代表什么。但是,如果文本中行尾的数字表示场景编号,则可以使用()捕获这些编号并在替换文本中替换它们,如下所示:

 v <- gsub(s, pattern = " ([0-9]{1,3})\\.$", replacement = "Scene \\1")

v使用
grep(coco,pattern=“[^Level].[0-9].$”,value=TRUE)查找您显示的文本中的哪些字符串。运行前面的代码,我可以找到为什么我使用[^level]在我的r脚本中不包含level的来源谢谢,谢谢!!这是我从昨天开始一直在寻找的东西,但我没有在网上找到它。作品
 v <- gsub(s, pattern = " ([0-9]{1,3})\\.$", replacement = "Scene \\1")