Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为嵌套在R中列表中的矩阵重命名列_R_Matrix_Lapply - Fatal编程技术网

为嵌套在R中列表中的矩阵重命名列

为嵌套在R中列表中的矩阵重命名列,r,matrix,lapply,R,Matrix,Lapply,我有一个包含几个矩阵的列表。每个矩阵中的行是唯一的,但列表示每个矩阵中通用的变量 下面的示例提供了我拥有的数据类型的示例: mat1 <- matrix(sample(1:100, 10, replace=TRUE), 2, 5) mat2 <- matrix(sample(1:100, 15, replace=TRUE), 3, 5) mat3 <- matrix(sample(1:100, 20, replace=TRUE), 4, 5) lst <-

我有一个包含几个矩阵的列表。每个矩阵中的行是唯一的,但列表示每个矩阵中通用的变量

下面的示例提供了我拥有的数据类型的示例:

  mat1 <- matrix(sample(1:100, 10, replace=TRUE), 2, 5)
  mat2 <- matrix(sample(1:100, 15, replace=TRUE), 3, 5)
  mat3 <- matrix(sample(1:100, 20, replace=TRUE), 4, 5)
  lst <- list(mat1, mat2, mat3)

mat1这有点过分,但是您的函数可能会返回矩阵,而不仅仅是名称

lst <- lapply(lst, function(x) {colnames(x) <- LETTERS[1:5];x})

是的,这很有效。事情很简单。谢谢你的帮助。
  lst <- lapply(lst, function(x) colnames(x) <- LETTERS[1:5]
 for(i in 1:length(lst)){colnames(lst[[i]]) <- LETTERS[1:5]}
lst <- lapply(lst, function(x) {colnames(x) <- LETTERS[1:5];x})