【问题标题】:How to get rid of extra spaces before and after commas on R Shiny text output?如何摆脱 R Shiny 文本输出中逗号前后的多余空格?
【发布时间】:2018-12-04 14:31:57
【问题描述】:

我想知道如何去除我的 R Shiny 应用程序的文本输出中出现的多余空格。

这是它的编码方式:

output$summary <- renderText ({
  isolate({
    paste("The power of this independent samples t-test, with population means of", 
          input$mu_1,"and", input$mu_2,
          ", standard deviations of", input$sigma_1, "and", input$sigma_2, 
          ", and sample sizes of", input$N_1, "and", input$N_2, ", is", Power)
  })
})


Power = mean(out.df$p.value < .05)

Power})

}

然而,在应用程序上,它会显示为:

此独立样本 t 检验的功效为 0.770562770562771,总体均值为 10 和 13,标准差为 2 和 5,样本大小为 21 和 27,

如您所见,逗号之前出现了额外的空格,我想知道如何才能摆脱这些空格?我试过 sep = "" 但这只是将所有数字组合在一起。不确定我是否把它放在正确的地方?

无论如何,提前谢谢!

玛戈

【问题讨论】:

    标签: r shiny removing-whitespace


    【解决方案1】:

    使用 sep = "" 在文本中定义空格,

    paste("The power of this independent samples t-test, with population means of ", 
      input$mu_1," and ", input$mu_2,
      ", standard deviations of ", input$sigma_1, " and ", input$sigma_2, 
      ", and sample sizes of ", input$N_1, " and ", input$N_2, ", is ", Power, sep = "")
    
    # [1] "The power of this independent samples t-test, with population means of 1 and 1, 
    # standard deviations of 1 and 1, and sample sizes of 1 and 1, is 1"
    

    【讨论】:

    • 非常感谢!这解决了我的问题! :)
    【解决方案2】:

    粘贴函数中 sep 的默认值为 " "。您应该使用 paste0(没有 sep 值)或在 paste 调用中设置 sep=""

    【讨论】:

      猜你喜欢
      • 2014-07-08
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      相关资源
      最近更新 更多