2014-12-07 87 views
1

我有兩個數字列表,我想以閃亮的文本格式輸出,但我無法輸出多行。說這兩個名單分別是:輸出多行文本

violations1 <- c(1,2,3,5) 
violations2 <- c(66,354,78) 

和輸出我想看看:

Violations of Type 1: 1, 2, 3, 4, 5 
Violations of Type 2: 66, 354, 78 

但是當我使用

paste("Violations of Type 1:", violations1, "Violations of Type 2:", violations2) 

我得到

[1] "Violations of Type 1: 1 Violations of Type 2: 66" 
[2] "Violations of Type 1: 2 Violations of Type 2: 354" 
[3] "Violations of Type 1: 3 Violations of Type 2: 78" 
[4] "Violations of Type 1: 5 Violations of Type 2: 66" 

回答

4

使用collapse選項paste

#data 
violations1 <- c(1,2,3,5) 
violations2 <- c(66,354,78) 

#result 
paste("Violations of Type 1:",paste(violations1,collapse = ",")) 
#[1] "Violations of Type 1: 1,2,3,5" 
paste("Violations of Type 2:",paste(violations2,collapse = ",")) 
#[1] "Violations of Type 2: 66,354,78"