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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:26:34+00:00 2026-05-26T03:26:34+00:00

I want to generate a row (with zero ammount) for each missing month (until

  • 0

I want to generate a row (with zero ammount) for each missing month (until the current) in the following dataframe. Can you please give me a hand in this? Thanks!

   trans_date       ammount
1  2004-12-01        2968.91
2  2005-04-01         500.62
3  2005-05-01         434.30
4  2005-06-01         549.15
5  2005-07-01         276.77
6  2005-09-01         548.64
7  2005-10-01         761.69
8  2005-11-01         636.77
9  2005-12-01        1517.58
10 2006-03-01         719.09
11 2006-04-01        1231.88
12 2006-05-01         580.46
13 2006-07-01        1468.43
14 2006-10-01         692.22
15 2006-11-01         505.81
16 2006-12-01        1589.70
17 2007-03-01        1559.82
18 2007-06-01         764.98
19 2007-07-01         964.77
20 2007-09-01         405.18
21 2007-11-01         112.42
22 2007-12-01        1134.08
23 2008-02-01         269.72
24 2008-03-01         208.96
25 2008-04-01         353.58
26 2008-05-01         756.00
27 2008-06-01         747.85
28 2008-07-01         781.62
29 2008-09-01         195.36
30 2008-10-01         424.24
31 2008-12-01         166.23
32 2009-02-01         237.11
33 2009-04-01         110.94
34 2009-07-01         191.29
35 2009-11-01         153.42
36 2009-12-01         222.87
37 2010-09-01        1259.97
38 2010-11-01         375.61
39 2010-12-01         496.48
40 2011-02-01         360.07
41 2011-03-01         324.95
42 2011-04-01         566.93
43 2011-06-01         281.19
44 2011-08-01         428.04

'data.frame':   44 obs. of  2 variables:
 $ trans_date     : Date, format: "2004-12-01" "2005-04-01" "2005-05-01" "2005-06-01" ...
 $ ammount: num  2969 501 434 549 277 ...
  • 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-26T03:26:35+00:00Added an answer on May 26, 2026 at 3:26 am

    you can use seq.Date and merge:

    > str(df)
    'data.frame':   44 obs. of  2 variables:
     $ trans_date: Date, format: "2004-12-01" "2005-04-01" "2005-05-01" "2005-06-01" ...
     $ ammount   : num  2969 501 434 549 277 ...
    > mns <- data.frame(trans_date = seq.Date(min(df$trans_date), max(df$trans_date), by = "month"))
    > df2 <- merge(mns, df, all = TRUE)
    > df2$ammount <- ifelse(is.na(df2$ammount), 0, df2$ammount)
    > head(df2)
      trans_date ammount
    1 2004-12-01 2968.91
    2 2005-01-01    0.00
    3 2005-02-01    0.00
    4 2005-03-01    0.00
    5 2005-04-01  500.62
    6 2005-05-01  434.30
    

    and if you need months until current, use this:

    mns <- data.frame(trans_date = seq.Date(min(df$trans_date), Sys.Date(), by = "month"))
    

    note that it is sufficient to call simply seq instead of seq.Date if the parameters are Date class.

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

Sidebar

Related Questions

I want to generate some test data so for each row in a table
I have the following input <row test=1 /> and want to generate the following
I want to generate a list in C#. I am missing python's list comprehensions.
I want to generate random colours which can be attractive in pie charts.I have
I need to generate a table from a list of objects. Each row will
I would like to generate the following output, using a single row from a
I want to generate a grid where people can select one or more cells
Let's say I have a class of 30 students and want generate every possible
I want to generate a thumbnail preview of videos in Java. I'm mostly JMF
I want to generate some XML in a stored procedure based on data in

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.