为什么cat()只执行第一个" \ n"在参数"标签"

时间:2017-03-22 02:59:06

标签: r cat

我编写了以下代码来测试"标签" cat()的参数有效:

df <- data.frame(A=1:3, B=4:6, C=7:9)
cat(summary(df), file="df.txt", fill=102, sep="\n ", labels=c("A\n", "B\n", "C\n"))

我希望文件&#34; df.txt&#34;看起来像:

A
 Min.   :1.0  
 1st Qu.:1.5  
 Median :2.0  
 Mean   :2.0  
 3rd Qu.:2.5  
 Max.   :3.0  

B
 Min.   :4.0  
 1st Qu.:4.5  
 Median :5.0  
 Mean   :5.0  
 3rd Qu.:5.5  
 Max.   :6.0  

C
 Min.   :7.0  
 1st Qu.:7.5  
 Median :8.0  
 Mean   :8.0  
 3rd Qu.:8.5  
 Max.   :9.0  

但我明白了:

A
 Min.   :1.0  
 1st Qu.:1.5  
 Median :2.0  
 Mean   :2.0  
 3rd Qu.:2.5  
 Max.   :3.0  

B\n Min.   :4.0  
 1st Qu.:4.5  
 Median :5.0  
 Mean   :5.0  
 3rd Qu.:5.5  
 Max.   :6.0  

C\n Min.   :7.0  
 1st Qu.:7.5  
 Median :8.0  
 Mean   :8.0  
 3rd Qu.:8.5  
 Max.   :9.0  

我的问题是为什么第一个&#34; \ n&#34;标签是有效的,另一个不是?

0 个答案:

没有答案