r - 在 R 中的打印语句中添加换行符

标签 r

这个问题在这里已经有了答案:





Printing newlines with print() in R

(4 个回答)


7年前关闭。




使用打印功能打印到屏幕时,我希望一行出现在一行上,而下一行出现在第二行上。

用这条线

print( 
    paste( 
        "hey I want this to be line one", "and this to be line two", "would be great if you could help"
    )
)

我想要这个打印

[1]“嘿,我希望这是第一行

[2] 如果你能帮忙的话,这是第二行就好了”

最佳答案

我假设您的示例输出实际上应该是三行而不是两行...您应该使用 cat而不是 print ,并添加 sep="\n"paste陈述:

 cat(paste("hey I want this to be line one", 
           "and this to be line two", 
           "would be great if you could help" ,sep="\n"))

输出:
hey I want this to be line one
and this to be line two
would be great if you could help

关于r - 在 R 中的打印语句中添加换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24072315/

相关文章:

html - Rvest 网页抓取带来仅包含列名称的空数据表

r - 如何用R提取包含大量0值的列?

javascript - R 中的 Highcharts 依赖轮

r - 将 x=y 线添加到 ggplot2 中的 hexplot

r - R 文本数据中最常见的短语

r - 生成N个随机整数,总和为R中的M

R coxph() 错误 : object 'Ccoxmart' not found

r - 如何从 R 中的数据框中删除重复且相同的行?

r - 在 R 中针对不同的初始条件模拟 ODE 模型

r - 如何在 ggplot2 中调整 geom_tile 的比例?