combine the values from two column into one
2
0
Entering edit mode
Nikul Soni ▴ 80
@nikul-soni-5917
Last seen 8.2 years ago
Sweden
Dear experts, I have an object in working environment with 6 columns and a row names. lets say 6 columns is divided as 2 x 3 where the first two columns contains the data from same group but one has only up (positive values) and the other has only dn (negative values) regulated genes and so on. what i want to do is to combine those 2 column together and have 3 column at the end from starting 6 column for further plotting. Can anybody assist me on how to perform this loop. i guess that this might be very easy if i had a programming background but unfortunately not. Any help is extremely appreciated. Thanks, Nikul -- सर्वेsत्र सुखिन: सन्तु सर्वे सन्तु निरामया: | सर्वे भद्राणि पश्यन्तु मा कश्चित दु:ख माप्नुयात || [[alternative HTML version deleted]]
• 716 views
ADD COMMENT
0
Entering edit mode
@michael-lawrence-3846
Last seen 2.4 years ago
United States
I think it would help to see a head() of your matrix and what exactly you mean by combining the columns. On Thu, Oct 31, 2013 at 7:13 AM, Nikul Soni <soninikul007@gmail.com> wrote: > Dear experts, > > I have an object in working environment with 6 columns and a row names. > lets say 6 columns is divided as 2 x 3 where the first two columns contains > the data from same group but one has only up (positive values) and the > other has only dn (negative values) regulated genes and so on. what i want > to do is to combine those 2 column together and have 3 column at the end > from starting 6 column for further plotting. Can anybody assist me on how > to perform this loop. > > i guess that this might be very easy if i had a programming background but > unfortunately not. Any help is extremely appreciated. > > Thanks, > > Nikul > -- > सर्वेsत्र सुखिन: सन्तु सर्वे सन्तु निरामया: | > सर्वे भद्राणि पश्यन्तु मा कश्चित दु:ख माप्नुयात || > > [[alternative HTML version deleted]] > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
@martin-rijlaarsdam-6043
Last seen 9.6 years ago
Hi, I think this is what you are looking for. Best, Martin x=matrix(1:18,nrow=3,ncol=6) #demo data with 3 rows and 6 columns print(x) #see the demo data out=matrix(NA,nrow=dim(x)[1]*2,ncol=dim(x)[2]/2) #prepare the output matrix with twice as much rows as x and half the nr of columns for (i in 1:dim(x)[2]/2) { cur_cols=c(2*i-1,2*i) #loop through the pairs of columns, 1+2, 3+4, etc. out[,i]=c(x[,cur_cols[1]],x[,cur_cols[2]]) #merge both columns into one #and move on to the next pair... } print(out) #see the new matrix #this example will work with any nr of rows and columns as long as the paired columns are adjacent and (naturally) the nr of columns is even. -- M.A. (Martin) Rijlaarsdam MSc. MD Erasmus MC - University Medical Center Rotterdam Department of Pathology Room Be-432b Shipping adress: P.O. Box 2040, 3000 CA Rotterdam, The Netherlands Visiting adress: Dr. Molewaterplein 50, 3015 GE Rotterdam, The Netherlands Email: m.a.rijlaarsdam@gmail.com Mobile: +31 6 45408508 Telephone (work): +31 10 7033409 Fax +31 10 7044365 Website: http://www.martinrijlaarsdam.nl On Thu, Oct 31, 2013 at 3:13 PM, Nikul Soni <soninikul007@gmail.com> wrote: > Dear experts, > > I have an object in working environment with 6 columns and a row names. > lets say 6 columns is divided as 2 x 3 where the first two columns contains > the data from same group but one has only up (positive values) and the > other has only dn (negative values) regulated genes and so on. what i want > to do is to combine those 2 column together and have 3 column at the end > from starting 6 column for further plotting. Can anybody assist me on how > to perform this loop. > > i guess that this might be very easy if i had a programming background but > unfortunately not. Any help is extremely appreciated. > > Thanks, > > Nikul > -- > सर्वेsत्र सुखिन: सन्तु सर्वे सन्तु निरामया: | > सर्वे भद्राणि पश्यन्तु मा कश्चित दु:ख माप्नुयात || > > [[alternative HTML version deleted]] > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 789 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6