reconhub / aweek

Convert dates to arbitrary week definitions :calendar:
https://www.repidemicsconsortium.org/aweek
Other
17 stars 4 forks source link

Add data.frame.aweek method #8

Closed zkamvar closed 5 years ago

zkamvar commented 5 years ago

Currently, it's only possible to create aweek data frames by inserting the column. Creating the data.frame.aweek() method would allow users to create data frames on the fly with aweek columns:

library('aweek')
d <- as.Date("2011-02-08") + 1:10
w <- date2week(d)
data.frame(w, d)
#> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors): cannot coerce class '"aweek"' to a data.frame
df <- data.frame(d)
df$w <- w
df
#>             d          w
#> 1  2011-02-09 2011-W06-3
#> 2  2011-02-10 2011-W06-4
#> 3  2011-02-11 2011-W06-5
#> 4  2011-02-12 2011-W06-6
#> 5  2011-02-13 2011-W06-7
#> 6  2011-02-14 2011-W07-1
#> 7  2011-02-15 2011-W07-2
#> 8  2011-02-16 2011-W07-3
#> 9  2011-02-17 2011-W07-4
#> 10 2011-02-18 2011-W07-5
# Tibbles work
tibble::tibble(w = w, d = d)
#> # A tibble: 10 x 2
#>    w           d         
#>    <S3: aweek> <date>    
#>  1 2011-W06-3  2011-02-09
#>  2 2011-W06-4  2011-02-10
#>  3 2011-W06-5  2011-02-11
#>  4 2011-W06-6  2011-02-12
#>  5 2011-W06-7  2011-02-13
#>  6 2011-W07-1  2011-02-14
#>  7 2011-W07-2  2011-02-15
#>  8 2011-W07-3  2011-02-16
#>  9 2011-W07-4  2011-02-17
#> 10 2011-W07-5  2011-02-18

Created on 2019-03-11 by the reprex package (v0.2.1)