Dear R sages, I used the function rbind to combine a matrix (M) and a vector (Fert) to get a new matrix (A). This was fine. The issue is however, that the new matrix A has as its row names the name of the vector Fert, even though I set teh new vector A to have dimnames=NULL. See short code below fyi. *Fert<-c(0,1,5) * *M <- matrix(0, 2, 3) diag(M) <- c(0.3,0.5) * *A<- as.matrix(rbind(Fert,M),dimnames=NULL) A* Any insights as to how to remove the row names from the new vector would be greatly appreciated. Many thanks, Tony [[alternative HTML version deleted]]
Hi, You can either use: A<-as.matrix(rbind(M,Fert)) dimnames(A)<- list(NULL,NULL) ?A #???? [,1] [,2] [,3] #[1,]? 0.3? 0.0??? 0 #[2,]? 0.0? 0.5??? 0 #[3,]? 0.0? 1.0??? 5 #or matrix(rbind(M,Fert),3,3) A.K. ? ----- Original Message ----- From: tony toca <meddee1000 at gmail.com> To: r-help at r-project.org Cc: Sent: Thursday, September 19, 2013 8:39 AM Subject: [R] (no subject) Dear R sages, I used the function rbind to combine a matrix (M) and a vector (Fert) to get a new matrix (A). This was fine. The issue is however, that the new matrix A has as its row names the name of the vector Fert, even though I set teh new vector A to have dimnames=NULL. See short code below fyi. *Fert<-c(0,1,5) * *M <- matrix(0, 2, 3) diag(M) <- c(0.3,0.5) * *A<- as.matrix(rbind(Fert,M),dimnames=NULL) A* Any insights as to how to remove the row names from the new vector would be greatly appreciated. Many thanks, Tony ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
Hi Tony, The dimnames parameter is only in the matrix() function, not in the as.matrix() function. #So you can do: A <- matrix(rbind(Fert,M), nrow = nrow(rbind(Fert,M))) A #This for example will allow you to name your row and colums. B <- matrix(rbind(Fert,M), nrow = nrow(rbind(Fert,M)), dimnames list(c("r1" , "r2", "r3"), c("c1", "c2", "c3"))) B Richard On Thu, Sep 19, 2013 at 5:39 AM, tony toca <meddee1000@gmail.com> wrote:> Dear R sages, > > I used the function rbind to combine a matrix (M) and a vector (Fert) to > get a new matrix (A). This was fine. > > The issue is however, that the new matrix A has as its row names the name > of the vector Fert, even though I set teh new vector A to have > dimnames=NULL. See short code below fyi. > > *Fert<-c(0,1,5) > * > *M <- matrix(0, 2, 3) > diag(M) <- c(0.3,0.5) > * > *A<- as.matrix(rbind(Fert,M),dimnames=NULL) > A* > > > Any insights as to how to remove the row names from the new vector would be > greatly appreciated. > > Many thanks, > Tony > > [[alternative HTML version deleted]] > > ______________________________________________ > 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]]