Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想命名列表的级别,就像在命名矩阵的行rownames()和colnames()列时一样。
rownames()
colnames()
例子:
a<-matrix(rep(1,4),2,2) b<-matrix(rep(2,9),3,3) list<-list(a,b) print(list)
[[1]]我不想在第一级返回,而是希望列表使用一些字符串,如“矩阵 a”。也许这很简单。
[[1]]
只需使用names:
names
names(list) = c("A","B") > list $A [,1] [,2] [1,] 1 1 [2,] 1 1 $B [,1] [,2] [,3] [1,] 2 2 2 [2,] 2 2 2 [3,] 2 2 2 list[["A"]] [,1] [,2] [1,] 1 1 [2,] 1 1
请注意,一般来说,使用 R 保留字(例如list变量名)并不是一个好习惯。
list