Hi, Try this: mat1<- as.matrix(read.table(text=" 1 1 3 2 3 1 1 2 3 3 2 ",sep="",header=FALSE)) res<-lapply(1:3,function(i) which(mat1==i)) names(res)<- c("a","c","b") res #$a #[1] 1 2 6 7
#$c #[1] 4 8 11 #$b #[1] 3 5 9 10 A.K. ----- Original Message ----- From: eliza botto <eliza_bo...@hotmail.com> To: "r-help@r-project.org" <r-help@r-project.org> Cc: Sent: Wednesday, March 6, 2013 6:26 AM Subject: [R] combining column having same values Dear useRs, I have a matrix in the following form [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] 1 1 3 2 3 1 1 2 3 3 2 and following is my desired output (combining the column headers, having same values). a<-1,2,6,7 b<-3,5,9,10 c<-4,8,11 Thanks in advance Elisa [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.