【问题标题】:Display a list of matrices without row and column names显示没有行名和列名的矩阵列表
【发布时间】:2018-06-25 16:02:31
【问题描述】:

我想显示一个没有小的 [1,] 和 [,1] 行和列指示符的矩阵列表(不是单个矩阵,正如其他地方所询问的那样)。

例如,给定myList:

myList <- list(matrix(c(1,2,3,4,5,6), nrow = 2), matrix(c(1,2,3,4,5,6), nrow = 3))
names(myList) <- c("This is the first matrix:", "This is the second matrix:")

我正在寻找一些将输出的函数myFunction()

> myFunction(myList)
$`This is the first matrix:`
 1    3    5
 2    4    6

$`This is the second matrix:`
 1    4
 2    5
 3    6

如果它可以消除列表名称周围的 $... 以便显示:

This is the first matrix:
 1    3    5
 2    4    6

This is the second matrix:
 1    4
 2    5
 3    6

在阅读了所有相关问题后,我已经尝试过

 myList %>% lapply(print, row.names = F)
 myList %>% lapply(prmatrix, collab = NULL, rowlab = NULL)
 myList %>% lapply(write.table, sep = " ",  row.names = F, col.names = F) 

但没有一个按预期工作。

【问题讨论】:

    标签: r matrix lapply names write.table


    【解决方案1】:

    所以你只是缺少标题?像这样的东西怎么样

    library(purrr) #for walk2()
    print_with_name <- function(mat, name) {
      cat(name,"\n")
      write.table(mat, sep = " ",  row.names = F, col.names = F)
    }
    myList %>% walk2(., names(.), print_with_name) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多