Can somebody tell me that, if I do some arithmetic calculation over 2
matrices then how the column names and row names are preserved? It seems
that, for multiplication, column names and row names of the 2nd matrix are
preserved and for additional, there seems not having any explicit rule:
> set.seed(1)
> dat1 <- matrix(rnorm(25), 5); colnames(dat1) = rownames(dat1) =
paste("mat1", 1:5, sep="")
> dat2 <- matrix(rnorm(25), 5); colnames(dat2) = rownames(dat2) =
paste("mat2", 1:5, sep="")
> dat3 <- matrix(rnorm(25), 5); colnames(dat3) = rownames(dat3) =
paste("mat3", 1:5, sep="")
> dat1
mat11 mat12 mat13 mat14 mat15
mat11 -0.6264538 -0.8204684 1.5117812 -0.04493361 0.91897737
mat12 0.1836433 0.4874291 0.3898432 -0.01619026 0.78213630
mat13 -0.8356286 0.7383247 -0.6212406 0.94383621 0.07456498
mat14 1.5952808 0.5757814 -2.2146999 0.82122120 -1.98935170
mat15 0.3295078 -0.3053884 1.1249309 0.59390132 0.61982575
> dat2
mat21 mat22 mat23 mat24 mat25
mat21 -0.05612874 1.35867955 -0.4149946 -0.1645236 -0.7074952
mat22 -0.15579551 -0.10278773 -0.3942900 -0.2533617 0.3645820
mat23 -1.47075238 0.38767161 -0.0593134 0.6969634 0.7685329
mat24 -0.47815006 -0.05380504 1.1000254 0.5566632 -0.1123462
mat25 0.41794156 -1.37705956 0.7631757 -0.6887557 0.8811077
> dat1 %*% dat2 + dat3
mat21 mat22 mat23 mat24 mat25
mat11 -1.2567987 0.5365897 3.5473394 0.89542630 2.5962144
mat12 -0.9370075 -1.0928568 0.2483355 -2.23467503 0.3284073
mat13 0.7665543 -2.6496778 1.8774045 1.45703219 0.9533289
mat14 0.7245671 4.5147054 -1.3445549 0.02866729 -5.3999956
mat15 -0.2173109 -0.1053570 0.3000135 2.88350373 -0.2541405
Can somebody finalize me what is the **rule** for preserving column names
and row names for matrix arithmatics?
Thanks,
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.