Um texto embutido e sem conjunto de caracteres especificado associado... Nome: n?o dispon?vel Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071123/d7912656/attachment.pl
Try this (not a lot of error checking -- assumes values 1-5 are in the matrix and in my.id): new.matrix <- my.df$my.value[match(my.matrix, my.df$my.id)] dim(new.matrix) <- dim(my.matrix) On Nov 23, 2007 4:13 PM, Milton Cezar Ribeiro <milton_ruser at yahoo.com.br> wrote:> Dear all, > > I have a matrix which values varying from 1 to 5. > I also have a table with a column that match with matrix values (=my.id). > > my.matrix<-matrix(sample(1:5,100,replace=T),nc=10) > image(my.matrix) > > my.df<-data.frame(cbind(my.id=1:5,my.value=c(0.1,0.3,0.2,0.9,1))) > my.df > > How can I create a new matrix, where the values of this matrix is my.value when the value of my.matrix match with my.df$my.id > > I can do it in a for() looping, but my matrix are so big (2000 x 2000) and I need to it about 1,000 times. > > Thanks in advance, > > Miltinho > > > > para armazenamento! > > [[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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Here's one way. new.matrix <- my.matrix new.matrix[] <- with(my.df, my.value[match(my.matrix, my.id)]) -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Milton Cezar Ribeiro Sent: Saturday, 24 November 2007 7:14 AM To: R-help Subject: [R] updating matrix from a dataframe Dear all, I have a matrix which values varying from 1 to 5. I also have a table with a column that match with matrix values (=my.id). my.matrix<-matrix(sample(1:5,100,replace=T),nc=10) image(my.matrix) my.df<-data.frame(cbind(my.id=1:5,my.value=c(0.1,0.3,0.2,0.9,1))) my.df How can I create a new matrix, where the values of this matrix is my.value when the value of my.matrix match with my.df$my.id I can do it in a for() looping, but my matrix are so big (2000 x 2000) and I need to it about 1,000 times. Thanks in advance, Miltinho para armazenamento! [[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.