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

  • Home
  • SEARCH
  • 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 7965395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:08:37+00:00 2026-06-04T06:08:37+00:00

I have a DateTime vector within a data.frame where the data frame is made

  • 0

I have a DateTime vector within a data.frame where the data frame is made up of 8760 observations representing hourly intervals throughout the year e.g.

2010-01-01 00:00
2010-01-01 01:00
2010-01-01 02:00
2010-01-01 03:00

and so on.

I would like to create a data.frame which has the original DateTime vector as the first column and then the hourly values in the second column e.g.

2010-01-01 00:00          00:00
2010-01-01 01:00          01:00

How can this be achieved?

  • 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-04T06:08:39+00:00Added an answer on June 4, 2026 at 6:08 am

    Use format or strptime to extract the time information.

    Create a POSIXct vector:

    x <- seq(as.POSIXct("2012-05-21"), by=("+1 hour"), length.out=5)
    

    Extract the time:

    data.frame(
      date=x,
      time=format(x, "%H:%M")
    )
    
                     date  time
    1 2012-05-21 00:00:00 00:00
    2 2012-05-21 01:00:00 01:00
    3 2012-05-21 02:00:00 02:00
    4 2012-05-21 03:00:00 03:00
    5 2012-05-21 04:00:00 04:00
    

    If the input vector is a character vector, then you have to convert to POSIXct first:

    Create some data

    dat <- data.frame(
      DateTime=format(seq(as.POSIXct("2012-05-21"), by=("+1 hour"), length.out=5), format="%Y-%m-%d %H:%M")
    )
    dat
              DateTime
    1 2012-05-21 00:00
    2 2012-05-21 01:00
    3 2012-05-21 02:00
    4 2012-05-21 03:00
    5 2012-05-21 04:00
    

    Split time out:

    data.frame(
      DateTime=dat$DateTime,
      time=format(as.POSIXct(dat$DateTime, format="%Y-%m-%d %H:%M"), format="%H:%M")
    )
    
              DateTime  time
    1 2012-05-21 00:00 00:00
    2 2012-05-21 01:00 01:00
    3 2012-05-21 02:00 02:00
    4 2012-05-21 03:00 03:00
    5 2012-05-21 04:00 04:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a vector of datetime values, I needed to create a data.frame containing datetimes
I have datetime value as 2010-04-07 09:00:00.000 2010-04-07 14:30:00.000 how to convert the 14:30
I have a datagrid which populated by some data from sqlserver.I have datetime filed
I have datetime data in string format like this: Sat Mar 24 23:59:59 GMT
I have a datetime variable in my application. Its value is 01/09/2010 00:00:00. I
If I have DateTime date = new DateTime(1/31/2010); and I call date.AddMonth(1) . Will
I have DateTime structure for an old data format that I don't have access
I have a DateTime column row and I declare a date string: Row: 2010-08-27
I have a datetime column in db that I want to transform into a
I have a DateTime field in SQL Server for some products expiration (ExpirationDate). I

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.