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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:08:26+00:00 2026-06-10T16:08:26+00:00

I have a character string of the date in Year-week format as such: weeks.strings

  • 0

I have a character string of the date in Year-week format as such:

weeks.strings <- c("2002-26", "2002-27", "2002-28", "2002-29", "2002-30", "2002-31")

However, converting this character to Date class results in a loss of week identifier:

> as.Date(weeks.strings, format="%Y-%U")
[1] "2002-08-28" "2002-08-28" "2002-08-28" "2002-08-28" "2002-08-28"
[6] "2002-08-28"

As shown above, the format is converted into year- concatenated with today’s date, so any information about the original week is lost (ex – when using the format function or strptime to try and coerce back into the original format.

One solution I found in a help group is to specify the day of the week:

as.Date(weeks.strings, format="%Y-%u %U")
[1] "2002-02-12" "2002-02-19" "2002-02-26" "2002-03-05" "2002-01-02"
[6] "2002-01-09"

But it looks like this results in incorrect week numbering (doesn’t match the original string).

Any guidance would be appreciated.

  • 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-10T16:08:28+00:00Added an answer on June 10, 2026 at 4:08 pm

    You just need to add a weekday to your weeks.strings in order to make the dates unambiguous (adapted from Jim Holtman’s answer on R-help).

    as.Date(paste(weeks.strings,1),"%Y-%U %u")
    

    As pointed out in the comments, the Date class is not appropriate if the dates span a long horizon because–at some point–the chosen weekday will not exist in the first/last week of the year. In that case you could use a numeric vector where the whole portion is the year and the decimal portion is the fraction of weeks/year. For example:

    wkstr <- sprintf("%d-%02d", rep(2000:2012,each=53), 0:52)
    yrwk <- lapply(strsplit(wkstr, "-"), as.numeric)
    yrwk <- sapply(yrwk, function(x) x[1]+x[2]/53)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that contains a czech character. the string is 0bálka This
i have a date string looks like this : 8/30/1987 at this time i
I have a date column with dates stored as strings, such as 20120817. Unfortunately,
After converting a date/time character string into POSIXlt using strptime, I am left with
I have this SQL Server query which is returning Conversion failed when converting date
I have a set of date strings in the following format: $date = 'month_name
Possible Duplicate: Count specific character occurances in string I have a delimeter in string
I need to get the last character of a string. Say I have testers
I have a very long String and I want to read character by character
I have a big string having at most 100000 character. Instead of using string.charAt[index]

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.