Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data.frame.aweek method #8

Closed
zkamvar opened this issue Mar 11, 2019 · 0 comments · Fixed by #21
Closed

Add data.frame.aweek method #8

zkamvar opened this issue Mar 11, 2019 · 0 comments · Fixed by #21
Labels
enhancement New feature or request

Comments

@zkamvar
Copy link
Member

zkamvar commented Mar 11, 2019

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)

@zkamvar zkamvar added the enhancement New feature or request label Mar 11, 2019
zkamvar added a commit that referenced this issue Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant