Hi every one I?m new to R and I cant figure our how to use the loop to do the following task, any help would be very kind of every one. I have a file called (table3.txt) that contains over 1000 row and over 40 columns. So for example first row would look like that Deafness, EYA4, DIAPH1, MYO7A, TECTA, COL11A2, POU4F3, MYH9, ACTG1, MYO6 I want the loop stamens to loop thro each row and take first cell which is (Deafness and second which is EYA4) and but it on the button of the file and then take the first cell which is (Deafness again and the third cell which is the DIAPH1) and put it on the button of the file. And so on till I end up with two columns one consists all the disease and one consist all the genes. -- View this message in context: http://n4.nabble.com/R-loop-tp1979620p1979620.html Sent from the R help mailing list archive at Nabble.com.
I'm not sure I completely understand your question, but I think the solution to your problem is the reshape function in the reshape package. Here is a silly example of how it would work:> V<-matrix(rbinom(15,4,.5),nrow=3) > X<-data.frame(A=c("A","B","C"),V=V) > XA V.1 V.2 V.3 V.4 V.5 1 A 1 2 3 3 3 2 B 4 3 0 2 2 3 C 2 3 2 1 2> reshape(X,direction="long",varying=c("V.1","V.2","V.3","V.4","V.5"))A time V id 1.1 A 1 1 1 2.1 B 1 4 2 3.1 C 1 2 3 1.2 A 2 2 1 2.2 B 2 3 2 3.2 C 2 3 3 1.3 A 3 3 1 2.3 B 3 0 2 3.3 C 3 2 3 1.4 A 4 3 1 2.4 B 4 2 2 3.4 C 4 1 3 1.5 A 5 3 1 2.5 B 5 2 2 3.5 C 5 2 3 Your two columns of interest are A and V. The time column lets you know from which column the V came. -tgs On Fri, Apr 16, 2010 at 6:35 AM, mhalsham <mhalsham@bradford.ac.uk> wrote:> > Hi every one I’m new to R and I cant figure our how to use the loop to do > the > following task, any help would be very kind of every one. > I have a file called (table3.txt) that contains over 1000 row and over 40 > columns. > So for example first row would look like that > > Deafness, EYA4, DIAPH1, MYO7A, TECTA, COL11A2, POU4F3, > MYH9, ACTG1, > MYO6 > > I want the loop stamens to loop thro each row and take first cell which is > (Deafness and second which is EYA4) and but it on the button of the file > and > then take the first cell which is (Deafness again and the third cell which > is the DIAPH1) and put it on the button of the file. And so on till I end > up > with two columns one consists all the disease and one consist all the > genes. > > -- > View this message in context: > http://n4.nabble.com/R-loop-tp1979620p1979620.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Thanks a lot for the help, but it?s not what I needed. -- View this message in context: http://r.789695.n4.nabble.com/R-loop-tp1979620p2020386.html Sent from the R help mailing list archive at Nabble.com.
On Fri, Apr 23, 2010 at 11:14 AM, mhalsham <mhalsham at bradford.ac.uk> wrote:> > Hi > Yes I have managed to read the file (Table2.txt) > The command I have used > a<- read.table("table3.txt", fill=TRUE, header=FALSE) > If I read the first row the result output will be like that. > a[1,] > > Result would be > > ? ? ? ?V1 ? V2 ? ? V3 ? ?V4 ? ?V5 ? ? ?V6 ? ? V7 ? V8 ? ?V9 ?V10 ?V11 ? V12 > 1 Deafness EYA4 DIAPH1 MYO7A TECTA COL11A2 POU4F3 MYH9 ACTG1 MYO6 GJB3 KCNQ4 > ? ?V13 ?V14 ?V15 ?V16 ?V17 ?V18 ? V19 ? V20 ?V21 ? V22 ? ? V23 ? V24 ? ?V25 > 1 GRHL2 GJB2 GJB6 TMC1 DSPP CRYM MYH14 DFNA5 COCH MYO1A TMPRSS3 CDH23 ATP2B2 > ? V26 ? V27 ?V28 ? ?V29 ? ?V30 ? V31 V32 > 1 STRC USH1C OTOA PCDH15 CLDN14 MYO3A >Did you try my code in that case? I think that does what you wanted. /Gustaf
Hi Gustaf Thank you for the help, but I have over 1000 records, I can?t write it all in the code I didn?t get the code I?m sorry. Regards Mohamad Al-shammari -- View this message in context: http://r.789695.n4.nabble.com/R-loop-tp1979620p2051726.html Sent from the R help mailing list archive at Nabble.com.