# User:Timothee Flutre/Notebook/Postdoc/2011/11/09

(Difference between revisions)
 Revision as of 15:37, 9 November 2011 (view source) (Autocreate 2011/11/09 Entry for User:Timothee_Flutre/Notebook/Postdoc)← Previous diff Revision as of 15:47, 9 November 2011 (view source) (→Entry title: replace rownames with mapping when different order)Next diff → Line 7: Line 7: ==Entry title== ==Entry title== - * Insert content here... + * in R, replace the row names of a matrix by their new names when the order is different (but assuming one-to-one mapping): + + links <- data.frame(id1=c("a","b","c"), id2=c("1","2","3"), stringsAsFactors=FALSE) + mat <- matrix(runif(3*10), nrow=3) + rownames(mat) <- c("b","c","a") + new.rownames <- unlist(lapply(rownames(mat), function(i){links\$id2[which(links\$id1 == i)]})) + rownames(mat) <- new.rownames

## Revision as of 15:47, 9 November 2011

Project name Main project page
Previous entry      Next entry

## Entry title

• in R, replace the row names of a matrix by their new names when the order is different (but assuming one-to-one mapping):
```links <- data.frame(id1=c("a","b","c"), id2=c("1","2","3"), stringsAsFactors=FALSE)
mat <- matrix(runif(3*10), nrow=3)
rownames(mat) <- c("b","c","a")
rownames(mat) <- new.rownames
```