Hi there!
I have this 24x24 matrix with a lot of numbers from 1-24. Where I want to turn every cell with the value of X (eg. 3) into the row.name of the X'th row (eg. name3)
What I have
row.names V1 V2 V3
name1 1 3 10
name2 3 20 1
name3 5 13 2
... .. .. ..
name24 19 3 4
What I want to do now, is turn all these numbers into a character string equvivalent to the i'th row name so a 1 should be converted to name1 and so forth.
What I need
row.names V1 V2 V3
name1 name1 name3 name10
name2 name3 name20 name1
name3 name5 name13 name2
... .. .. ..
name24 name19 name3 name4
I figured it may be nessesary to convert the matrix into a dataframe, but I don't know exacly how to get there from what I have.
Thanks! //HK
Use basic
[
to match the values to the rownames.Here's an example.
Assume we're starting with this:
Here's what
rownames(m)[m]
looks like:Use
[]
to preserve the dims of the original matrix while replacing the values: