hi, if I have 20 x 3 data.frame, how to split it into 10 x 6 (moving the lower part of 10x3 to column) or 5 x 12 thanks -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. "Did you always know?" "No, I did not. But I believed..." ---Matrix III
If I understand your question: df <- data.frame(x=rnorm(20), y=rnorm(20), z=rnorm(20)) df <- as.matrix(df) dim(df) dim(df) <- c(10,6) dim(df) <- c(5,12) On 29/10/2007, Weiwei Shi <helprhelp@gmail.com> wrote:> > hi, > > if I have 20 x 3 data.frame, how to split it into > 10 x 6 (moving the lower part of 10x3 to column) > > or > > 5 x 12 > > thanks > > -- > Weiwei Shi, Ph.D > Research Scientist > GeneGO, Inc. > > "Did you always know?" > "No, I did not. But I believed..." > ---Matrix III > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Henrique Dallazuanna wrote:>If I understand your question: > >df <- data.frame(x=rnorm(20), y=rnorm(20), z=rnorm(20)) >df <- as.matrix(df) >dim(df) >dim(df) <- c(10,6) >dim(df) <- c(5,12) > >On 29/10/2007, Weiwei Shi <helprhelp at gmail.com> wrote: > > >>hi, >> >>if I have 20 x 3 data.frame, how to split it into >>10 x 6 (moving the lower part of 10x3 to column) >> >>or >> >>5 x 12 >> >>thanks >> >> >>Hi, I am not sure that the produced result is what is looked for; however the question is not clear to me either. The indicated code gives: df=data.frame(x=1:4,y=5:8) df=as.matrix(df) df newdf=df dim(newdf) = c(2,4) newdf while I would have thought that : newdf=cbind(df[1:2,], df[3:4,]) newdf was what was looked for. But there may be a quicker way. Regards, Thibaut. -- ###################################### Thibaut JOMBART CNRS UMR 5558 - Laboratoire de Biom?trie et Biologie Evolutive Universite Lyon 1 43 bd du 11 novembre 1918 69622 Villeurbanne Cedex T?l. : 04.72.43.29.35 Fax : 04.72.43.13.88 jombart at biomserv.univ-lyon1.fr http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en http://pbil.univ-lyon1.fr/software/adegenet/
maybe you need this q<-matrix(1:60,20,3) matrix(q,10,6) matrix(q,5,12) 2007/10/29, Weiwei Shi <helprhelp at gmail.com>:> hi, > > if I have 20 x 3 data.frame, how to split it into > 10 x 6 (moving the lower part of 10x3 to column) > > or > > 5 x 12 > > thanks > > -- > Weiwei Shi, Ph.D > Research Scientist > GeneGO, Inc. > > "Did you always know?" > "No, I did not. But I believed..." > ---Matrix III > > ______________________________________________ > R-help at 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. >