After cbindor - rbindusing the table object (for example, adding a stock of sums or somesuch), the names dimnames are lost (see y). I found this “workaround”, but wondered if it has a bag solution that looks less cracked. Perhaps something that can be done on the fly? I would like to save a class object table.
> (x <- table(1:3, sample(1:3), dnn = c("rows", "cols")))
cols
rows 1 2 3
1 1 0 0
2 0 0 1
3 0 1 0
> (y <- cbind(x, "4" = 4:6)) # "rows" and "cols" get lost
1 2 3 4
1 1 0 0 4
2 0 0 1 5
3 0 1 0 6
> names(dimnames(y)) <- names(dimnames(x))
> y
cols
rows 1 2 3 4
1 1 0 0 4
2 0 0 1 5
3 0 1 0 6
source
share