在r中使用cat时如何在换行符后删除不需要的空间

问题描述

> cat(c("A\n","B"))
A
 B

我不知道为什么会这样。如何解决

解决方法

您可以使用:

cat(c("A\n","B"),sep='')

或者:

cat(c('A','B'),sep='\n')