【问题标题】:Outputting multiple lines of text输出多行文本
【发布时间】:2014-12-07 21:11:19
【问题描述】:

我有两个数字列表,我想以闪亮的文本输出,但我很难输出多行。假设这两个列表是:

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" 

【问题讨论】:

    标签: r string concatenation


    【解决方案1】:

    使用pastecollapse 选项:

    #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"
    

    【讨论】:

      猜你喜欢
      • 2014-09-09
      • 2017-02-01
      • 2018-10-29
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 2014-06-07
      相关资源
      最近更新 更多