[R] updating matrix from a dataframe

jim holtman jholtman at gmail.com
Fri Nov 23 22:34:42 CET 2007


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?



More information about the R-help mailing list