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 4039704
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:39:04+00:00 2026-05-20T12:39:04+00:00

Dear all, I have a data frame which comes directly from a sensor. The

  • 0

Dear all, I have a data frame which comes directly from a sensor. The data provide the date and time in a single column. I want R to be able to recognise this data and then create an adjacent column in the data frame which gives a number that corresponds to a new day in the time and date column. For example 25/02/2011 13:34 in data$time.date would give 1 in the new column data$day, and 26/02/2011 13:34 in data$time.date would get 2 and so on….

Does anyone know how to go about solving this? Thanks in advance for any help.

  • 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-05-20T12:39:05+00:00Added an answer on May 20, 2026 at 12:39 pm

    You can use cut() and convert to numeric the factor resulting from that call. Here is an example with dummy data:

    > sdate <- as.POSIXlt("25/02/2011 13:34", format = "%d/%m/%Y %H:%M")
    > edate <- as.POSIXlt("02/03/2011 13:34", format = "%d/%m/%Y %H:%M")
    > df <- data.frame(dt = seq(from = sdate, to = edate, by = "hours"))
    > head(df)
                       dt
    1 2011-02-25 13:34:00
    2 2011-02-25 14:34:00
    3 2011-02-25 15:34:00
    4 2011-02-25 16:34:00
    5 2011-02-25 17:34:00
    6 2011-02-25 18:34:00
    

    We cut the date time column into days using cut(). This results in a factor with the dates as labels. We convert this factor to numerics to get 1, 2, ...:

    > df <- within(df, day <- cut(dt, "day", labels = FALSE))
    > head(df, 13)
                        dt day
    1  2011-02-25 13:34:00   1
    2  2011-02-25 14:34:00   1
    3  2011-02-25 15:34:00   1
    4  2011-02-25 16:34:00   1
    5  2011-02-25 17:34:00   1
    6  2011-02-25 18:34:00   1
    7  2011-02-25 19:34:00   1
    8  2011-02-25 20:34:00   1
    9  2011-02-25 21:34:00   1
    10 2011-02-25 22:34:00   1
    11 2011-02-25 23:34:00   1
    12 2011-02-26 00:34:00   2
    13 2011-02-26 01:34:00   2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dear all..i have this data inside DB: line model serial fa01 kd-g335ud 105x0001 fa01
Dear all: In advance, thank you for your time. Lately, I have decided to
dear all..i have some data at DB. name Range bla 123x9901-123x0000 //it means range
dear all. i have a lot of data in my database. after that i
dear all, i'll take some data from the database. and join two tables.the code
dear all.. i have a DB which built use Mysql. for this case, i
Dear all, I have a problem in MySQL: I failed to execute DELETE FROM
Dear g++ hackers, I have the following question. When some data of an object
dear all..i have a textfield <tr> <td> <td><input type=text id=model_name></td> </td> </tr> and a
Dear all I have database of website link, it list out in main file

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.