I have the following matrix:> dat[,1] [,2] [,3] [,4] foo 0.7574657 0.2104075 0.02922241 0.002705617 foo 0.0000000 0.0000000 0.00000000 0.000000000 foo 0.0000000 0.0000000 0.00000000 0.000000000 foo 0.0000000 0.0000000 0.00000000 0.000000000 foo 0.0000000 0.0000000 0.00000000 0.000000000 foo 0.0000000 0.0000000 0.00000000 0.000000000 and given this:> new_names <- c("k0","k1","k2,"k3","k4","k5");How can I get this? [,1] [,2] [,3] [,4] k0 0.7574657 0.2104075 0.02922241 0.002705617 k1 0.0000000 0.0000000 0.00000000 0.000000000 k2 0.0000000 0.0000000 0.00000000 0.000000000 k3 0.0000000 0.0000000 0.00000000 0.000000000 k4 0.0000000 0.0000000 0.00000000 0.000000000 k5 0.0000000 0.0000000 0.00000000 0.000000000 best, GV.
example:> x<-c(1,1,1) > y<-c(2,2,2) > m<-rbind(x,y) > m[,1] [,2] [,3] x 1 1 1 y 2 2 2> dimnames(m)[[1]] [1] "x" "y" [[2]] NULL> dimnames(m)[[1]]<-c("a","b") > m[,1] [,2] [,3] a 1 1 1 b 2 2 2 Am 15.05.2012 um 11:19 schrieb Gundala Viswanath:> I have the following matrix: >> dat > > [,1] [,2] [,3] [,4] > foo 0.7574657 0.2104075 0.02922241 0.002705617 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > > and given this: > >> new_names <- c("k0","k1","k2,"k3","k4","k5"); > > > How can I get this? > > > [,1] [,2] [,3] [,4] > k0 0.7574657 0.2104075 0.02922241 0.002705617 > k1 0.0000000 0.0000000 0.00000000 0.000000000 > k2 0.0000000 0.0000000 0.00000000 0.000000000 > k3 0.0000000 0.0000000 0.00000000 0.000000000 > k4 0.0000000 0.0000000 0.00000000 0.000000000 > k5 0.0000000 0.0000000 0.00000000 0.000000000 > > best, > GV. > > ______________________________________________ > R-help@r-project.org 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.[[alternative HTML version deleted]]
Hello,> A = matrix(0, 3,3) > rownames(A) = c("A", "B", "C") > A[,1] [,2] [,3] A 0 0 0 B 0 0 0 C 0 0 0 HTH, Thanks, Paolo On 15 May 2012 10:19, Gundala Viswanath <gundalav@gmail.com> wrote:> I have the following matrix: > > dat > > [,1] [,2] [,3] [,4] > foo 0.7574657 0.2104075 0.02922241 0.002705617 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > foo 0.0000000 0.0000000 0.00000000 0.000000000 > > and given this: > > > new_names <- c("k0","k1","k2,"k3","k4","k5"); > > > How can I get this? > > > [,1] [,2] [,3] [,4] > k0 0.7574657 0.2104075 0.02922241 0.002705617 > k1 0.0000000 0.0000000 0.00000000 0.000000000 > k2 0.0000000 0.0000000 0.00000000 0.000000000 > k3 0.0000000 0.0000000 0.00000000 0.000000000 > k4 0.0000000 0.0000000 0.00000000 0.000000000 > k5 0.0000000 0.0000000 0.00000000 0.000000000 > > best, > GV. > > ______________________________________________ > R-help@r-project.org 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. >[[alternative HTML version deleted]]