R:用公共字符连接未知数量的字符串

R:用公共字符连接未知数量的字符串,r,R,目标是在每个句子前面插入。例如: df=(info="this text doesn't mean anything and it's only here as a demonstration. You can replace this with anything else and I want to somehow wrap this text") 我想要的是: "this text doesn't mean anything and it's only here as a demonstr

目标是在每个句子前面插入

。例如:

df=(info="this text doesn't mean anything and it's only here as a demonstration. You can replace this with anything else and I want to somehow wrap this text")
我想要的是:

"this text doesn't mean anything and it's only here as a demonstration." "<br>" "You can replace this with anything else and I want to somehow wrap this text"
“此文本没有任何意义,仅作为演示。”“
”您可以用任何其他内容替换此文本,我想以某种方式包装此文本”
以下是我的最佳尝试,但不知何故它不起作用:

paste(strsplit(as.character(df$info)[1],"[.]"),sep="<br>")
粘贴(strsplit(作为字符(df$info)[1],“[.]”,sep=“
”)
如果点指定了可以使用的句子
gsub

gsub('\\.', '. <br>', df)
gsub(“\\.”,“.
”,df)
这将返回:

[1] "this text doesn't mean anything and it's only here as a demonstration. <br> You can replace this with anything else and I want to somehow wrap this text"
[1]“此文本没有任何意义,仅作为演示。
您可以用任何其他内容替换此文本,我想以某种方式包装此文本”
您的尝试不起作用的原因是
strsplit
正在返回一个列表,而您希望使用
[[1]]
粘贴该列表的第一个元素。。。然后用

粘贴(strsplit(如.character(df$info)[1],“[.]”[[1]],collapse=“.br>”)

你想要一个长度为3的向量,其中第二个元素是“
”,还是一个长度为1的向量,句子之间有
paste(strsplit(as.character(df$info)[1],"[.] ")[[1]], collapse =". <br>")