[R] splitting a long dataframe

David Winsemius dwinsemius at comcast.net
Wed Dec 26 08:40:13 CET 2012


On Dec 25, 2012, at 9:52 AM, Swagath wrote:

> Dear all...Merry Christmas
>
> I would like to split a long dataframe. The dataframe looks like this
>
> x<-c('0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00',  
> '2:30:00', '3:00:00', '0:00:00', '0:30:00', '1:00:00', '1:30:00',  
> '2:00:00', '2:30:00', '3:00:00', '3:30:00', '4:00:00','0:00:00',  
> '0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00', '3:00:00',  
> '0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00',  
> '3:00:00' , '3:30:00', '4:00:00')
>
> y=seq(1:32)
>
> data1=data.frame(x,y)
>
> i want to split in such a way that the output looks like
>
> 0:00:00  1  8 17 24
> 0:30:00  2  9 18 25
> 1:00:00  3 10 19 26
> 1:30:00  4 11 20 27
> 2:00:00  5 12 21 28
> 2:30:00  6 13 22 29
> 3:00:00  7 14 23 30
> 3:30:00 NA 15 NA 31
> 4:00:00 NA 16 NA 32
>
> any ideas or functions that i look into for doing this?

You already have 3 distinct solutions on StackOverflow.
>


David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list