如何追加两个矩阵而不丢失dimname?在R中追加两个矩阵而不丢失dimname
设置一些数据:
m1 <- structure(c(35.3, 31.7, 25.9, 15.8),
.Dim = c(2L, 2L),
.Dimnames = structure(list(
Treatment = c("no1", "yes1"), Loc = c("North", "South")),
.Names = c("Treatment", "Loc")))
m2 <- structure(c(9.5, 9.6, 7.4, 4.0),
.Dim = c(2L, 2L),
.Dimnames = structure(list(
Treatment = c("no2", "yes2"), Loc = c("North", "South")),
.Names = c("Treatment", "Loc")))
其中给出:
> m1
Loc
Treatment North South
no1 35.3 25.9
yes1 31.7 15.8
> m2
Loc
Treatment North South
no2 9.5 7.4
yes2 9.6 4.0
但如果我附上他们rbind
:
> rbind(m1,m2)
North South
no1 35.3 25.9
yes1 31.7 15.8
no2 9.5 7.4
yes2 9.6 4.0
我已经失去了 “治疗” 和行和列维度上的“Loc”名称。
是否有直接的方法来追加两个而不丢失dimname?
在这种情况下,可以假定dimnames是相同的,或者假设我们只是想要第一个对象具有的任何dimnames。浮现在脑海
相关答案一个问题:http://stackoverflow.com/questions/9213468/r-losing-names-of-a-table-after-cbind-or-rbind – thelatemail 2014-09-03 04:14:19