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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:16:03+00:00 2026-06-18T10:16:03+00:00

I’d like to go from this: years ——- 1994 2001 . . To this:

  • 0

I’d like to go from this:

  years
 -------
  1994
  2001
   .
   .

To this:

int dates
 ------
  8793    # 1994-01-28
  8824    # 1994-02-28
  8852    # 1994-03-28
  8883    # 1994-04-28
  8913    # 1994-05-28
  8944    # 1994-06-28
  8974    # 1994-07-28
  9005    # 1994-08-28
  9036    # 1994-09-28
  9066    # 1994-10-28
  9097    # 1994-11-28
  9127    # 1994-12-28
 11350    # 2001-01-28
 11381    # 2001-02-28
 11409    # 2001-03-28
 11440    # 2001-04-28
 11470    # 2001-05-28
 11501    # 2001-06-28
 11531    # 2001-07-28
 11562    # 2001-08-28
 11593    # 2001-09-28
 11623    # 2001-10-28
 11654    # 2001-11-28
 11684    # 2001-12-28
   .
   .

i.e. periodizing each year into 12 dates (the 28th each month of that year) as 1970-base integers.

What is the most efficient way of doing this?

My attempt is painfully slow!

require(data.table)

# Sample data
dt <- data.table(year=c(1994,2001)) # edit

# Create results table
data <- data.table(dates=integer())

for (i in 1:12) {
    temp <- dt
    temp$dates <- as.integer(as.Date(paste(temp$year, "-", sprintf( "%02d",i),"-28", sep="")))
    temp <- subset(temp, select=dates)
    data <- rbind(temp,data)
}

# Sort
data <- data[with(data, order(dates)),]
  • 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-18T10:16:04+00:00Added an answer on June 18, 2026 at 10:16 am

    Here’s a one-liner:

    as.integer(as.Date(apply(expand.grid(1:12,c(1994,2001)), 1, 
                             function(x)paste(x[2], x[1], 28,sep="-"))))
    
     [1]  8793  8824  8852  8883  8913  8944  8974  9005  9036  9066  9097  9127 11350 11381 11409 11440 11470 11501
    [19] 11531 11562 11593 11623 11654 11684
    

    And here the step by step explanation:

    expand.grid(1:12, c(1994,2001))
     Var1 Var2
    1     1 1994
    2     2 1994
    3     3 1994
    4     4 1994
    5     5 1994
    6     6 1994
    7     7 1994
    8     8 1994
    9     9 1994
    10   10 1994
    11   11 1994
    12   12 1994
    13    1 2001
    14    2 2001
    15    3 2001
    16    4 2001
    17    5 2001
    18    6 2001
    19    7 2001
    20    8 2001
    21    9 2001
    22   10 2001
    23   11 2001
    24   12 2001
    

    To that you apply on every row function paste(). Then convert to a Date object that you then convert to an integer (by default 1970-base).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.