[R] updating matrix from a dataframe
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Sat Nov 24 02:50:12 CET 2007
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.
More information about the R-help
mailing list