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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:26:27+00:00 2026-06-17T15:26:27+00:00

I need to go from this id | date —————– A | 2000-01-13 A

  • 0

I need to go from this

 id  |    date
-----------------
  A  | 2000-01-13
  A  | 2000-01-18
  A  | 2000-01-25
  B  | 2012-10-10
  B  | 2012-10-11
  C  | 2005-07-25
  C  | 2005-07-31

to this

 id  |    date     | days from start
---------------------------
  A  | 2000-01-13  |  0
  A  | 2000-01-18  |  5
  A  | 2000-01-25  |  12
  A  | 2000-02-08  |  26
  B  | 2012-10-10  |  0
  B  | 2012-10-11  |  1
  C  | 2005-07-25  |  0
  C  | 2005-07-31  |  6

i.e. creating a variable that holds the number of days passed since the first date, grouped by id.

Any ideas?

  • 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-17T15:26:28+00:00Added an answer on June 17, 2026 at 3:26 pm

    Using data.table: (I assume the date column is character here. If its date format, then you can remove the as.Date(.) function call.

    df <- structure(list(id = c("A", "A", "A", "B", "B", "C", "C"), 
                 date = c("2000-01-13", "2000-01-18", "2000-01-25", "2012-10-10", 
                        "2012-10-11", "2005-07-25", "2005-07-31")), 
                 .Names = c("id", "date"), row.names = c(NA, -7L), 
                 class = "data.frame")
    require(data.table)
    dt <- data.table(df, key="id")
    dt[, days_from_start := cumsum(c(0, diff(as.Date(date)))),by=id]
    
    #    id       date days_from_start
    # 1:  A 2000-01-13               0
    # 2:  A 2000-01-18               5
    # 3:  A 2000-01-25              12
    # 4:  B 2012-10-10               0
    # 5:  B 2012-10-11               1
    # 6:  C 2005-07-25               0
    # 7:  C 2005-07-31               6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to obtain a Date object from this String:This is a example) M-27\nJUN-2012
I need to extract Asia from this array. How can i do that. Here
I need to get UserCarId(int) from this query and assign to int type variable.
I am using this date picker from jqueryui . If you look on that
I need to convert date from this format: 2011-11-04T18:30:49Z To this format: MM/dd/yy hh:mm:SS
I have php code that returns this from a database, [ { Time: 2012-11-27
I need to add 28 days to a Date - I have tried this:
I need to get a Date from an SQL Server Database (SQL Server 2000),
I need to convert a date from this format: 2002-10-10T12:00:00-05:00 (xs:dateTime as defined in
so, i need format JSON date from this format 9/30/2010 12:00:00 AM, it is

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.