Using R to count number of specific days in a specific month

rossi_182

I'm trying to count the number of Saturdays and then Sundays in a specific month within R.

So for example if you entered the month for example Feb-2014 into the function it would return 4 for Saturday and 4 for Sunday. But if you input Jan-2015 it would return 5 for Saturday and 4 for Sunday.

Any ideas?

Thomas

You can use lubridate for this. Here's a simple example. You'll have to pass it actual dates (not just months, though):

library("lubridate")
weekend_days <- function(x) {
  x <- as.Date(x)
  d <- days_in_month(x)
  d <- x + (0:(d-1))
  sum(wday(d) %in% c(1,7))
}

Some examples (for January and February 2012):

weekend_days("2012-01-01")
# [1] 9
weekend_days("2012-02-01")
# [1] 8

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Count the number of specific days of the month that have passed since a given date

From Dev

How to get the number of days in a specific month using Java Calendar?

From Dev

get number of working days in specific month

From Dev

Calculate Total Number Of Days Per Specific Month

From Dev

get number of working days in specific month

From Dev

Using Python to count the number of business days in a month?

From Dev

count number of days in a month in SAS

From Dev

Count the number of days from a specific date and data range

From Dev

Count the number of days from a specific date with ID as a "break variable"

From Dev

Count the number of days from a specific date with ID as a "break variable"

From Dev

need to count number of specific transitions in a vector in R

From Dev

R count number of specific string in data frame

From Dev

Postgres sql count number of days active in month

From Dev

Calculate number of days between specific date and today r

From Dev

Calculate number days between specific date and today's date in R

From Dev

Count number of rows with a specific MONTH in the date of a specific cell and a boolean condition in another cell

From Dev

Calculate the number of days between today and specific date using DAX in Powerpivot

From Dev

How to get all days in a month that are a specific weekday?

From Dev

Know the day and the month in number type of specific dates using moment

From Dev

java.time - Is there a function to find number of a specific day (day of week, or day of month) between two days?

From Dev

Return count of days in month using array formula

From Dev

get number of days in the CURRENT month using javascript

From Dev

Xquery - count the number of specific elements with specific attributes

From Dev

R: 3rd Wedndesday of a specific month using XTS

From Dev

R: 3rd Wedndesday of a specific month using XTS

From Dev

Count specific dates [R]

From Java

How to Count number of rows in every column that meets a specific criteria in R

From Dev

How to count number of records from specific cateogry using PHP MYSQL

From Dev

Count number of occurences of specific words in Excel sheet using python & xlrd

Related Related

  1. 1

    Count the number of specific days of the month that have passed since a given date

  2. 2

    How to get the number of days in a specific month using Java Calendar?

  3. 3

    get number of working days in specific month

  4. 4

    Calculate Total Number Of Days Per Specific Month

  5. 5

    get number of working days in specific month

  6. 6

    Using Python to count the number of business days in a month?

  7. 7

    count number of days in a month in SAS

  8. 8

    Count the number of days from a specific date and data range

  9. 9

    Count the number of days from a specific date with ID as a "break variable"

  10. 10

    Count the number of days from a specific date with ID as a "break variable"

  11. 11

    need to count number of specific transitions in a vector in R

  12. 12

    R count number of specific string in data frame

  13. 13

    Postgres sql count number of days active in month

  14. 14

    Calculate number of days between specific date and today r

  15. 15

    Calculate number days between specific date and today's date in R

  16. 16

    Count number of rows with a specific MONTH in the date of a specific cell and a boolean condition in another cell

  17. 17

    Calculate the number of days between today and specific date using DAX in Powerpivot

  18. 18

    How to get all days in a month that are a specific weekday?

  19. 19

    Know the day and the month in number type of specific dates using moment

  20. 20

    java.time - Is there a function to find number of a specific day (day of week, or day of month) between two days?

  21. 21

    Return count of days in month using array formula

  22. 22

    get number of days in the CURRENT month using javascript

  23. 23

    Xquery - count the number of specific elements with specific attributes

  24. 24

    R: 3rd Wedndesday of a specific month using XTS

  25. 25

    R: 3rd Wedndesday of a specific month using XTS

  26. 26

    Count specific dates [R]

  27. 27

    How to Count number of rows in every column that meets a specific criteria in R

  28. 28

    How to count number of records from specific cateogry using PHP MYSQL

  29. 29

    Count number of occurences of specific words in Excel sheet using python & xlrd

HotTag

Archive