Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9035377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:44:41+00:00 2026-06-16T08:44:41+00:00

Merry Christmas I would like to split a long dataframe. The dataframe looks like

  • 0

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? I tried using split function, but could not get it done.
Thanks a lot for your help and time.

The below solution by Matthew works best. However if i increase the cycle time for x

    x<-c('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', '4:30:00', '5:00:00', '5:30:00', '6:00:00', '6:30:00', '7:00:00', 
    '7:30:00','8:00:00', '8:30:00', '9:00:00', '9:30:00', '10:00:00', '10:30:00',
     '11:00:00','11:30: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', '4:30:00', '5:00:00', '5:30:00', '6:00:00', '6:30:00', 
    '7:00:00', '7:30:00','8:00:00', '8:30:00', '9:00:00', '9:30:00', '10:00:00', '10:30:00', 
    '11:00:00','11:30:00', '12:00:00', '12:30:00', '13:00:00', '13:30:00')

and use the same code, i get the following error:

    Error in match.names(clabs, names(xi)) : names do not match previous names

Cheers,
Swagath

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:44:43+00:00Added an answer on June 16, 2026 at 8:44 am

    If we can assume that each new cycle starts at 0:00:00 and that each new cycle will always include a 0:00:00, then we can easily use reshape() after creating a “time” variable using cumsum().

    data1 <- data.frame(
      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$times <- cumsum(data1$x == "0:00:00")
    reshape(data1, direction = "wide", idvar = "x", timevar = "times")
    #          x y.1 y.2 y.3 y.4
    # 1  0:00:00   1   8  17  24
    # 2  0:30:00   2   9  18  25
    # 3  1:00:00   3  10  19  26
    # 4  1:30:00   4  11  20  27
    # 5  2:00:00   5  12  21  28
    # 6  2:30:00   6  13  22  29
    # 7  3:00:00   7  14  23  30
    # 15 3:30:00  NA  15  NA  31
    # 16 4:00:00  NA  16  NA  32
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string 'Merry Christmas'. I want to separate this one as 'Merry'
Hi everybody and Merry Christmas. Please see this snippet of code. As you can
Is this possible? Basically, what I want to do is something like this: #includeIfItExists
First of all, Merry Christmas to everyone! Now to my question: Let's say I
First of all, Merry Christmas all! What I've been trying to do is real
Merry christmas everyone, I Know my way around SQL but I'm having a hard
Merry Christmas, in the spirit of the season I had an idea of a
Merry Christmas everybody :) I have a pointer problem. Although I´m familiar with pointer
Merry Christmas to everybody. I'm having a dilemma with a perl script. In my
Merry Christmas and Happy Holidays everyone! I'm trying to setup a listener on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.