epitools (version 0.09)

as.week: Convert date-time object in 'disease week'

Description

Converts date-time object into "disease week" with values of 0 to 53 and values 1 to 53

Usage

as.week(x, format = "%Y-%m-%d", first.day = "Sunday", before = 7, after = 7)

Arguments

x
character vector of dates to be converted into 'disease weeks'
format
default is standard date 'YYYY-mm-dd'
first.day
first day of first weeks starts with either 'Sunday' (default) or 'Monday'
before
number of days before minimum date in x; used in creating vector of possible dates of which x is a subset
after
number of days after maximum date in x; used in creating vector of possible dates of which x is a subset

Value

  • $jdates'Date' vector created from x
  • $jweeks0'disease week' vector created from x; week before week 1 takes the value of 0 in same year (default in R)
  • $jweeks'disease week' vector created from x; week before week 1 takes the value of 52 or 53 from previous year
  • $jstratumunique strata values for each week in jweeks
  • $jindexunique values for unique dates in x
  • $cdatesrange of possible calendar dates of which jdates is a subset
  • $cweeks0range of possible calendar weeks0 of which jweeks0 is a subset
  • $cweeksrange of possible calendar weeks of which jweeks is a subset
  • $cstratumunique strata values for each week in cweeks
  • $cindexunique values for unique dates in cdates; i.e., 1:length(cdates)

Details

In public health, reportable diseases are often reported by 'disease week' (either week of reporting or week of symptom onset). In R, weeks are numbered from 0 to 53 in the same year. The first day of week 1 starts with either the first Sunday or Monday of the year. The 'as.week' functions generates weeks numbered from 1 to 53. The week before week 1 takes on the value (52 or 53) from the last week of the previous year.

References

none

See Also

See also as.Date, strptime, DateTimeClasses

Examples

Run this code
mydates <- c("1/1/04", "1/2/04", "1/7/04", "1/14/04", "8/18/04");
as.week(mydates, format = "%m/%d/%y")

Run the code above in your browser using DataCamp Workspace