R 将字符串解析为数据帧

R 将字符串解析为数据帧,r,parsing,R,Parsing,我有一堆字符串,看起来像这样: [3] " 3. Wiki: Los Angeles 3:58pm; score:1.959502" [4] " 4. Wiki: Boston 6:58pm; score:1.959502" [5] " 5. Disambiguation: 'Boon; score:1.934644" [6] " 6. Wiki: The Note (album)\"; score:1.78693

我有一堆字符串,看起来像这样:

 [3] "  3. Wiki: Los Angeles 3:58pm; score:1.959502"        
 [4] "  4. Wiki: Boston 6:58pm; score:1.959502"             
 [5] "  5. Disambiguation: 'Boon; score:1.934644"            
 [6] "  6. Wiki: The Note (album)\"; score:1.786931"          
read.csv(text=sub("^  [0-9]*\\. (Wiki|Disambiguation): (.*); score:([0-9\\.]*)$","\"\\2\",\\3",ll),
         header=FALSE,stringsAsFactors=FALSE)
我将它们解析为如下数据帧:

 [3] "  3. Wiki: Los Angeles 3:58pm; score:1.959502"        
 [4] "  4. Wiki: Boston 6:58pm; score:1.959502"             
 [5] "  5. Disambiguation: 'Boon; score:1.934644"            
 [6] "  6. Wiki: The Note (album)\"; score:1.786931"          
read.csv(text=sub("^  [0-9]*\\. (Wiki|Disambiguation): (.*); score:([0-9\\.]*)$","\"\\2\",\\3",ll),
         header=FALSE,stringsAsFactors=FALSE)
问题在于我用引号括起来的
\\2
文本本身可能包含引号(双引号和单引号)


如何处理这个问题?

只需删除双引号:

ll <-  gsub('"', '', ll)

ll我在引起我悲伤的地方加了引号。在
,“\“\\2\”,
,“\'\\2\”
帮助中,是否将双引号改为单引号?sub仍然有效
sub(^[0-9]*\\(维基消歧):(.*);分数:([0-9\\.]*)$,“\'\''2'\',\\3','hello')