Skip to content
Prev 128124 / 398500 Next

how to split data.frame by row?

Henrique Dallazuanna wrote:

            
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.