[R] Build a matrix from another matrix by specifying the indexes
anna
lippelanna24 at hotmail.com
Tue Feb 2 21:07:01 CET 2010
Hello R specialists,
I have a base vector called vBase with 102 elements. I have another vector
vec1 which elements are only part of vBase but is shorter. I transform vec1
so I get a vector with the same size as vBase and with each common element
on the same indexed row. If a value is missing in vec1 then I put a Na like
this:
vec1 vBase
Amsterdam Amsterdam
Na Bruxelles
Dublin Dublin
Frankfurt Frankfurt
Paris Paris
This is how I did it: vec1 <- vec1[match(vBase,vec1)]
But what I really want to is the same but on a matrix columns, for example
mat <- cbind( vec1, vec2 ,vec3)
I found a way to make a match on each column:
indexes <- apply(mat, 2, match, x = vBase)
It returns me the indexes matrix but I don't know how each index column to
each mat column like I did for vec1 with vec1[]. Any idea?
-----
Anna Lippel
--
View this message in context: http://n4.nabble.com/Build-a-matrix-from-another-matrix-by-specifying-the-indexes-tp1460326p1460326.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list