Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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_String - Fatal编程技术网

R 连接字符串时添加新行?

R 连接字符串时添加新行?,r,string,R,String,我想将以下句子组合在一起,但我希望第二句作为一个新段落开始: Sentence 1: Premise: R is very useful for automating tasks at the office. Sentence 2: Conclusion: Therefore, we should learn R. 我希望这两句话如下: Premise: R is very useful for automating tasks at the office. Conclusion: Ther

我想将以下句子组合在一起,但我希望第二句作为一个新段落开始:

Sentence 1: Premise: R is very useful for automating tasks at the office.
Sentence 2: Conclusion: Therefore, we should learn R.
我希望这两句话如下:

Premise: R is very useful for automating tasks at the office.

Conclusion: Therefore, we should learn R.
以下是我迄今为止所尝试的:

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."
paragrah <- cat(sen.1, sen.2)

paragraph
Premise: R is very useful for automating tasks at the office. Conclusion: Therefore, we should learn R.
提前谢谢

我们可以使用writeLines函数,它将把分隔的字符串打印到不同的行中

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."

writeLines(c(sen.1, " ", sen.2))
Premise: R is very useful for automating tasks at the office.

Conclusion: Therefore, we should learn R.
我们可以使用writeLines函数,它将分隔的字符串打印到不同的行

sen.1 <- "Premise: R is very useful for automating tasks at the office."
sen.2 <- "Conclusion: Therefore, we should learn R."

writeLines(c(sen.1, " ", sen.2))
Premise: R is very useful for automating tasks at the office.

Conclusion: Therefore, we should learn R.
\n表示cat中的换行符,但请注意,它不返回任何值-只是打印到控制台,显然您可以使用capture.output解决这个问题

\n表示cat中的换行符,但请注意,它不返回任何值-只是打印到控制台,显然您可以使用capture.output解决这个问题


只需插入两个换行符\n:

参议员1 >结论:因此,我们应该学习R。 要保存为变量以备将来打印,请使用“粘贴”`
段落只需插入两个换行符\n:

参议员1 >结论:因此,我们应该学习R。 要保存为变量以备将来打印,请使用“粘贴”`
第catsen.1、n、sen.2段。要打印到控制台,要保存到变量capture.outputcatsen.1,\n,sen.2catsen.1,sen.2,sep='\n\n'@snoram:Hm,从我的角度看不起作用:@alistaire:起作用了!你能用“回答你的问题”按钮写出来吗?这样我就可以选择你的答案了。要打印到控制台,要保存到变量capture.outputcatsen.1,\n,sen.2catsen.1,sen.2,sep='\n\n'@snoram:Hm,从我的角度看不起作用:@alistaire:起作用了!你能用“回答你的问题”按钮写下这句话吗?这样我就可以选择你的答案了。你也可以用catsen.1,sen.2,sep=\n保存到一个文件中。另外,你不会在第三行中获得额外的空间。cat的默认分隔符是,这就是为什么在第1行之后和第3行之前插入了这些额外的空间。我会删除我的答案,因为它对@alistaire的添加很少,但这些伟大的评论值得一看。你也可以用catsen.1、sen.2保存到一个文件中,sep=\n更有意义。另外,第三行中不会有额外的空格。cat的默认分隔符是,这就是为什么在第1行之后和第3行之前插入这些额外空格的原因。我会删除我的答案,因为它对@alistaire的添加很少,但这些伟大的评论值得一看。