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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:46:17+00:00 2026-05-30T14:46:17+00:00

I have two dates begin <- as.Date(2007-05-20) end <- as.Date(2010-06-13) How can I count

  • 0

I have two dates

begin <- as.Date("2007-05-20")
end   <- as.Date("2010-06-13")

How can I count the days per year?

The output should maybe look like this

year   days
2007   226
2008   366
2009   365
2010   164
  • 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-30T14:46:18+00:00Added an answer on May 30, 2026 at 2:46 pm

    Let’s first create a proper date sequence:

    R> bd <- as.Date("2007-05-20")
    R> ed <- as.Date("2010-06-13")
    R> seqd <- seq(bd, ed, by="1 day")
    R> head(seqd)
    [1] "2007-05-20" "2007-05-21" "2007-05-22" "2007-05-23" "2007-05-24" "2007-05-25"
    

    We then create a helper function which, given a date, returns its year:

    R> getYear <- function(d) as.POSIXlt(d)$year + 1900
    R> getYear(head(seqd))
    [1] 2007 2007 2007 2007 2007 2007
    

    After that, we just call table() on what the helper returns from the date sequence:

    R> table(getYear(seqd))
    
    2007 2008 2009 2010 
     226  366  365  164 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two dates (parsed using str2time ). How can I tell if one
I have two dates: how do I compare which one is greater date in
i have two dates ValidFrom : 20-04-2010 validTo : 02-05-2010 i need to know
I have two dates in format(MM/dd/yyyy hh:mm:ss:SS). For the both dates I have converted
If I have two dates (ex. '8/18/2008' and '9/26/2008' ), what is the best
I am trying to compare two dates. I have this code which I thought
I would like to compare two dates in javascript. I have been doing some
I am trying to select between two dates, but in the table they have
I have two date entities, start_date and end_date and now I want to find
I have two Zend Date objects to work with: $now = Zend_Date::now(); $sessionStart =

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.