I want to write a function to rename the matrix rows and columns.
My function is
changeMatrixName<- function(mat){
nameRow<-vector(mode="character",length=nrow(mat))
nameCol<-vector(mode="character",length=ncol(mat))
nameCol<- colnames(mat)
nameRow<- rownames(mat)
#annotation[annotation$probeID==c("ILMN_1814092","ILMN_1668851"),]$symbol
rowGeneName<-vector(mode="character",length=nrow(mat))
colGeneName<-vector(mode="character",length=ncol(mat))
rowGeneName<-annotation[annotation$probeID==c(nameRow),]$symbol
colGeneName<-annotation[annotation$probeID==c(nameCol),]$symbol
row.names(mat)<-rowGeneName
col.names(mat)<-colGeneName
return(mat)
}
I have a test matrix like
ILMN_1814092 ILMN_1805104 ILMN_2070570 ILMN_2232084 ILMN_1704579
ILMN_1802380 4.972073e-03 0.016279737 0.0076933191 0.0214107369 0.001951975
ILMN_1753196 2.222289e-04 0.080954797 0.0389565797 0.0220420297 0.002545084
ILMN_1753830 1.657137e-05 0.009063726 0.0004676619 0.0008824427 0.007684124
When I run
test2<-changeMatrixName(test)
Error in
rownames<-
(x, value) : length of 'dimnames' [1] not equal to array extent In addition: Warning message: In annotation$probeID == c(nameRow) : longer object length is not a multiple of shorter object length