Nussenzveig, Roberto H.
2009-Feb-26 03:11 UTC
[R] How do I retrieve column and row names after comparing two matrices?
Hello, I have two matrices as shown below: Matrix 1 ID AB1 BC1 CD1 ... name1 1,1 2,1 0,2 ... name2 2,0 1,2 1,2 ... name3 0,2 1,1 2,0 ... name4 2,0 0,2 0,2 ... Matrix 2 ID AB2 BC2 CD2 ... name1 1,1 2,1 0,2 ... name2 2,0 1,2 1,2 ... name3 0,2 1,0 2,0 ... name4 2,0 0,2 0,2 ... Comparison of both matrices reports a unique difference based on the following code: informative<-which(matrix1!=matrix2) transitions<-napaste(matrix1,matrix2)[informative] unique_transitions<-unique(transitions) lfreq<-list(State_transitions=unique_transitions) lf<-as.data.frame(lfreq) plot(lf) write.table(lf,"C:\\ state_transitions.txt",sep="\t",quote=FALSE,row.names=TRUE) lf } state_trans_freqs() The result is reported as: 1 1,1 1,0 How can I identify the column name (BC1, BC2) and row name (name3, name3) that refers to this unique transition? Should I change my import and data parsing? cat("Reading Test calls.\n") calls<-read.delim("C:\\Test_calls", header=T) # Identify which data column contains ID. ID_id<-c(1) # Identify which data columns contain the matrix1 and matrix2 samples. matrix1_samples<-c(2,4,6,8,10) matrix2 _samples<-c(3,5,7,9,11) # Generate matrices of matrix1and matrix2 samples. matrix1<-as.vector(as.matrix(calls[ID_id, matrix1_samples])) matrix2 <-as.vector(as.matrix(calls[ID_id, matrix2 _samples])) Please help. Thanks. - ------------------------------------------------------------------ The information transmitted by this e-mail and any included attachments are from ARUP Laboratories and are intended only for the recipient. The information contained in this message is confidential and may constitute inside or non-public information under international, federal, or state securities laws, or protected health information and is intended only for the use of the recipient. Unauthorized forwarding, printing, copying, distributing, or use of such information is strictly prohibited and may be unlawful. If you are not the intended recipient, please promptly delete this e-mail and notify the sender of the delivery error or you may call ARUP Laboratories Compliance Hot Line in Salt Lake City, Utah USA at (+1 (800) 522-2787 ext. 2100 [[alternative HTML version deleted]]