[R] how to split data.frame by row?

Thibaut Jombart jombart at biomserv.univ-lyon1.fr
Mon Oct 29 17:57:59 CET 2007


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/



More information about the R-help mailing list