【问题标题】:How to avoid an empty vector when using the cat() function in R?在 R 中使用 cat() 函数时如何避免空向量?
【发布时间】:2019-01-11 18:33:54
【问题描述】:

我正在创建一个字符向量,我想在其中描述有关我的数据框列的信息。当我结合文本和函数时,我得到一个长度为 0 的空向量,调用我的向量是没有意义的。

我正在使用cat() 函数来执行此操作:

columns <- cat("Columns in dataset describe annotations for 28416 genes. Variables:", colnames(DATA)[c(1, 11, 12, 13, 14)], "present descriptive information, variables:", colnames(raw.data), "represent expression data of three experimental conditions.")

当我运行它时,它工作得很好。我得到一个段落。但是当我调用我的向量列时,我得到:NULL 顺便说一句,在这个例子中打印和粘贴没有用,因为它们为每个列名重复我的文本。我不需要。

谢谢!

【问题讨论】:

    标签: r string is-empty


    【解决方案1】:

    粘贴colnames 以及collapse

    columns <- paste("Columns in dataset describe annotations for 28416 genes. Variables:", paste(colnames(DATA)[c(1, 11, 12, 13, 14)], collapse = " "), "present descriptive information, variables:", paste(colnames(raw.data), collapse = " "), "represent expression data of three experimental conditions.")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 2023-02-16
      • 2021-06-30
      • 2021-04-07
      • 2020-10-06
      • 1970-01-01
      • 2018-04-06
      • 2020-01-17
      相关资源
      最近更新 更多