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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:13:21+00:00 2026-06-15T20:13:21+00:00

Given a vector of dates (could span multiple years): exampleDates = as.Date( 1 :

  • 0

Given a vector of dates (could span multiple years):

exampleDates = as.Date( 1 : 15, origin = as.Date( "2012-12-25" ) )

I’d like to generate an identifier that groups dates into weeks. So assuming a calendar that starts on Sunday:

  • the 26th to the 29th would produce the same identifier
  • the 30th through the 5th have the same id
  • the 6th through the 9th have the same id

Here’s a flawed attempt:

strftime( exampleDates , format = "%Y%W" )

It sees the 31th and the 1st as different weeks (no surprise). I’m looking for something similar to strftime that will generate an identifier (character, numeric, whatever) that I can use to group the dates by week.

I’m sure there’s some clever function out there already.

  • 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-15T20:13:22+00:00Added an answer on June 15, 2026 at 8:13 pm

    This will assign a unique integer to groups of dates that fall within a given week:

    origin <- as.Date("2012-12-9")  ## A Sunday
    weekID <- as.numeric(exampleDates - origin) %/% 7
    
    data.frame(date = exampleDates,
               weekday = weekdays(exampleDates),
               week = weekID)
    #          date   weekday week
    # 1  2012-12-26 Wednesday    2
    # 2  2012-12-27  Thursday    2
    # 3  2012-12-28    Friday    2
    # 4  2012-12-29  Saturday    2
    # 5  2012-12-30    Sunday    3
    # 6  2012-12-31    Monday    3
    # 7  2013-01-01   Tuesday    3
    # 8  2013-01-02 Wednesday    3
    # 9  2013-01-03  Thursday    3
    # 10 2013-01-04    Friday    3
    # 11 2013-01-05  Saturday    3
    # 12 2013-01-06    Sunday    4
    # 13 2013-01-07    Monday    4
    # 14 2013-01-08   Tuesday    4
    # 15 2013-01-09 Wednesday    4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a date I can access the appropriate element in a zoo vector. For
Given unit vector (0.5, 0.5) how could I find the angle (its direction)? Is
If a date vector has two-digit years, mdy() turns years between 00 and 68
Is there a way to easily generate java beans given a vector in clojure?
Given a vector of variables, transform the vector so that each variable is repeated
Given a vector of variables, transform the vector so that each variable is repeated
I'd like to reorder columns in my data.table x , given a character vector
I'm trying to write a function in R that, given a vector and a
I have a dataframe where the dates are given as hydrological years (October to
For a given vector like this, Vector<Temp> s = new Vector<Temp>(); s.add(new Temp(a,1)); s.add(new

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.